So, a colleague of mine recently ran into an issue where a tool was failing in updateParameters() because on a particular line, the list index was out of range.
Is the code in question (Error caused by line 3 in this snippet):
aprx = arcpy.mp.ArcGISProject('current')
mv = aprx.activeView
if str(mv).split(' ')[0].split('.')[2] == "Layout": #if a activeView returns a layout, get the map frame from it
mf = mv.listElements("MAPFRAME_ELEMENT")[0].map
else: #it's a map view
mf = mv.map
What we figured out is that trying to run the tool with an attribute table open and active was causing the issue.
Essentially, because ArcGISProject.activeView only sees Map or Layout Views, it was feeding line 3 a None object, which can't be split, acted upon, etc.
I'd prefer to avoid this sort of thing in the future.
Here are two options I can think of to fix this:
- If a table, etc. is open and active, return the map it belongs to
- Alternatively, return the last active map/layout.
- Recognize table, etc views in Active view, be able to check the type of the result.