How can I import an notebook that is not part of a project already?
I have a standalone notebook on a drive and the idea is allow other people to import this into their Pro projects. How can I do this?
I've only found this which does not answer my question.
Maybe the notebook can added to the computer and then accessed through the catalog pane?
Solved! Go to Solution.
I don't really use notebooks, so what I'm about to suggest may be erroneous? How about copying that external notebook file into the project folder then follow the instructions you link to, to add it to the project?
I don't really use notebooks, so what I'm about to suggest may be erroneous? How about copying that external notebook file into the project folder then follow the instructions you link to, to add it to the project?
To refer to an existing notebook with a static location, browse to the notebook file in the Catalog and Right Click → Add To Project.
But I assume that's not what you're looking for and you want the users to retain a copy of a "master" file in their own projects. In that case:
def import_notebook(project_path: str = "CURRENT"):
from os import path
import shutil
SOURCE_BOOK = r"\\the\path\to\the\notebook.ipynb"
prj = arcpy.mp.ArcGISProject(project_path)
new_book = path.join(prj.homeFolder, path.basename(SOURCE_BOOK))
shutil.copy(SOURCE_BOOK, new_book)
return new_book
And that's as far as Python can take you (unless I'm missing some obscure CIM method). The Pro SDK has an Add Item method but making an addon just to clone a book properly seems a bit much, you might be better off instructing the user to add the book themselves.
I think both of these are correct. I was just talking about using the Pro GUI and not doing it programmatically. The steps are essentially these I think:
I wasn't sure you could access the file system like this in Pro so this is now solved. Thanks!