Select to view content in your preferred language

ArcGIS Pro Notebook + activeView

2254
8
Jump to solution
07-09-2021 02:27 PM
Brian_Wilson
Honored Contributor

In a Notebook, "activeView" just seems to return None.

Is this expected or just a bug? Without the ability to affect the current map, it seems Notebooks are not very useful. Is there a workaround? Python windows are just a major pain compared to Notebooks.

Thanks

In ArcGIS Pro 2.8, this code works in a Python window but not in a notebook.

 

a = arcpy.mp.ArcGISProject("CURRENT")
v = a.activeView.camera
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
In  [25]:
Line 2:     v = a.activeView.camera

AttributeError: 'NoneType' object has no attribute 'camera'
---------------------------------------------------------------------------

 

 

0 Kudos
2 Solutions

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Gotcha. Yeah, Notebooks are really nice for developing ideas, you just happen to have found one of the spots where it won't work. What's especially odd is that if you have other panes open like Contents and Attributes, they will continue to refer to the last active map view even if the focus is on a Notebook window.

That said, if you add a script tool and just keep an external IDE open to edit it, you can still do a decent job of "debugging", even if it's a bit clunkier.

Alternately, you can use arcpy.mp to explicitly reference a MapFrame in a layout. You can activate the frame so that it behaves like a standard map view, enabling all your editing tools, etc.. You should be able to do all your work from the Layout view if you went that route.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
DannyMcVey
Esri Alum

FYI This has been fixed in ArcGIS Pro 3.0. A notebook opened alongside a map now works like the python window, allowing access to the open map through "activeview" as described above. The enables all kinds of fun interaction between the two.

View solution in original post

0 Kudos
8 Replies
jcarlson
MVP Esteemed Contributor

What exactly is your workflow you're trying to accomplish with your Notebook? From my own experience, the arcpy.mp module is a little better-suited for working with map frames in layouts, if you're looking to change the extent.

If you needed to affect the active view, you could always use a custom GP script. If it needs user input at various stages, you could build a Task which includes a custom GP script as part of a larger process.

- Josh Carlson
Kendall County GIS
0 Kudos
Brian_Wilson
Honored Contributor

I'd like to be able to use a notebook to test out some ideas before committing them to a tool. 

 

Specifically we want to zoom to a work area that is a tax map in the view, to work on edits there, so that will be the zoom tool, and then later want to set the extent for exporting map to pdf so that's a separate export tool. I played with creating a locator for the zoom tool but I don't have control over the scale there so both tools will be in a python toolbox when they are done. I have not tried working with layouts yet.

The export requires things like adjusting scale bars, a cancelled numbers table, etc that change for each page. It worked quite well in ArcMap and now I have to port it all to Pro. Quite fun so far.

I'd like to be able to drive the ArcGIS Pro session from a debugger but that's not supported. 

Using the Python window is so clunky. Sigh. Oh well. Maybe they'll fix Notebooks next year...

 

0 Kudos
jcarlson
MVP Esteemed Contributor

Gotcha. Yeah, Notebooks are really nice for developing ideas, you just happen to have found one of the spots where it won't work. What's especially odd is that if you have other panes open like Contents and Attributes, they will continue to refer to the last active map view even if the focus is on a Notebook window.

That said, if you add a script tool and just keep an external IDE open to edit it, you can still do a decent job of "debugging", even if it's a bit clunkier.

Alternately, you can use arcpy.mp to explicitly reference a MapFrame in a layout. You can activate the frame so that it behaves like a standard map view, enabling all your editing tools, etc.. You should be able to do all your work from the Layout view if you went that route.

- Josh Carlson
Kendall County GIS
0 Kudos
DanPatterson
MVP Esteemed Contributor

The help is explicit...

ArcGISProject—ArcGIS Pro | Documentation

activeMap

Note:
This property is designed to be executed from within the application using a script tool or the Python window. If a script is run outside of the application, None will always be returned.

activeview.png


... sort of retired...
0 Kudos
Brian_Wilson
Honored Contributor

..and that's why I explicitly said I'm running it inside the ArcGIS Pro application, in a Notebook. 😉

0 Kudos
DanPatterson
MVP Esteemed Contributor

and thats why it says in a script or the python window 😉


... sort of retired...
0 Kudos
mody_buchbinder
Frequent Contributor

I think there is no active view since the notebook is the "active view".

You can get the map using the listMaps with the name of the map or just the first on.

0 Kudos
DannyMcVey
Esri Alum

FYI This has been fixed in ArcGIS Pro 3.0. A notebook opened alongside a map now works like the python window, allowing access to the open map through "activeview" as described above. The enables all kinds of fun interaction between the two.

0 Kudos