Select to view content in your preferred language

How to import external notebook into Pro?

296
3
Jump to solution
01-09-2025 08:34 AM
chris_del101
Regular Contributor

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?

 

0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

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?

View solution in original post

0 Kudos
3 Replies
DuncanHornby
MVP Notable Contributor

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?

0 Kudos
DavidSolari
MVP Regular Contributor

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.

0 Kudos
chris_del101
Regular Contributor

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:

  • add the notebook to the computer so that Pro can access it.
  • in Pro (maybe from Catalog pane using Computer tab) right click 'add to project'.
  • Now it should appear under Notebooks

I wasn't sure you could access the file system like this in Pro so this is now solved. Thanks!

0 Kudos