Python scripting tool fails from Catalog Pane but works in Catalog View

278
1
11-07-2023 10:07 AM
GerryGabrisch
Occasional Contributor III

I have a Python scripting tool that will auto-export a layout to PDF or JPG, update a text box with the export  YYMMDDHHMMSS, and log who-what-where-when info to a CSV file.  I have been using this code in ArcGIS for years and recently upgraded the tool to work with Pro. 

Oddly, the  Pro tool works just fine when executed from the Toolbox section of the Catalog View but fails at line 50 when executed from a Catalog Pane.  Why would this be the case?  

Here is the error message:

 PYTHON ERRORS:
Traceback info:
  File "Z:\GISpublic\GerryG\Python3\SuperSaverArcPro\A1-SuperSaver.atbx#Script_supersaver.py", line 51, in <module>

Error Info:
'NoneType' object has no attribute 'listElements'

 and here is the offending code:

    mapnumber = get_time()
    
    #Get the name of the active map view....
    view = aprx.activeView
    
    ele = view.listElements("TEXT_ELEMENT", "mapnumber")[0]
    #assign the mapnumber to the map....
    ele.text = mapnumber

 Here is a link to the tool and the code:

https://github.com/LummiGIS/Auto-Export-Pro-Layout

0 Kudos
1 Reply
Brooks_Wilson
Occasional Contributor

I don't have a solution, but I think I understand why it's happening. 

From MapView—ArcGIS Pro | Documentation:

 The activeView property from the ArcGISProject class will either return a MapView object if a map view is active or it will return a Layout or Report object if a layout view or report view is active. Any other type of view will return None

I'm surprised it's not the opposite. When I have used ActiveView before and ran the tool from the Catalog Pane, the active view returns the map or layout that is active. But the Catalog View returns None. You can test the different returns of the ActiveView in the Python Window of Pro.

aprx = arcpy.mp.ArcGISProject('current')
mv = aprx.activeView
print (mv.name)

For me, my problem was getting an ActiveView when an attribute table was selected. I set my tool to not run until the ActiveView was a map or layout. 

You might see if ActiveMap works for your needs, it returns the activated map regardless of view pane.

 

Brooks Wilson
National ESRI Software Support Engineer
BLM - National Operations Center (NOC)
Contractor - Sanborn
Phone - 303-236-0503
Email - bhwilson@blm.gov