Select to view content in your preferred language

Listing open maps only in an ArcGIS Pro project using Python

1448
2
11-19-2021 02:27 AM
MattHowe
Frequent Contributor

I'm creating a script to process all layers in an ArcGIS Pro project but would only like it to process maps that the user has open in the current project and not all maps associated with the project.

aprx = arcpy.mp.ArcGISProject("CURRENT")
maps = aprx.listMaps()
for map in maps:
    layers = map.listLayers()
    for layer in layers:

 If I was looking at data sources for example, the above code would process layers in all maps even if they aren't currently open. 

How would I only process layers in open maps only?

Tags (3)
0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

From Map—ArcGIS Pro | Documentation

I don't see something that would process only the open maps (eg.  isOpen or equivalent).

There is also nothing in the arcgis project class

This would be a good candidate for an Idea


... sort of retired...
JaredPilbeam2
MVP Regular Contributor

Have you tried this? I would test it in Pro, but I'm all of a sudden getting Kernel Error, and none of my Notebooks are working... Apparently, It won't work in a stand-alone. You'd have to run it in a Pro Notebook or console.

import arcpy
aprx = arcpy.mp.ArcGISProject('CURRENT')
print(aprx.activeMap)

 Taken from: https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm