9

I try to do the following in ArcGIS Pro with ArcPy: I want to select the current map in a project, in which the user is currently working.

So far I have just one map so I can do it like this:

aprx = arcpy.mp.ArcGISProject("CURRENT")
s = aprx.listMaps("Scene")[0]
layerList = s.listLayers()

And then I do something with the selected features...

Now I have multiple maps and I don't want to iterrate through all layers in all maps. Is there some way to do something like this:

s = aprx.currentMap()

Or to test if the Map is the current one?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Dec 7, 2017 at 13:12

2 Answers 2

10

It felt like I spent about 6-8 hours trying to figure this out and it turns out its quite simple facepalm. Its mentioned at the top of the ArcGIS Project class page here:

http://pro.arcgis.com/en/pro-app/arcpy/mapping/arcgisproject-class.htm

Code I used to get the active map name was this:

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

So in short I believe what you're looking for is: activeMap

answered Oct 12, 2018 at 1:26
1
  • So the code to get the layers would be: aprx = arcpy.mp.ArcGISProject("CURRENT") theMap = aprx.activeMap #view? Map? layerList = theMap.listLayers() Commented Oct 3, 2022 at 2:36
1

I am not sure that the concept of a "current map" makes any sense when using ArcPy with ArcGIS Pro.

By "current map" you may mean the map which was active when your project was last saved but you will not always have an active map because when you last saved your project you may have had a layout active instead.

answered Dec 8, 2017 at 0:19
1
  • 1
    Yes you're right, the "current map" doesn't make sense in every case. In my case, I use the ArcPy-Script in a Toolbox where the user selects some features in a map or scene and then I change some attributes for the selected features. So it would be nice to know in which map the user is working so I only iterate through the layers of the current map and don't have to iterate through every layer in every map to find the selected features. Commented Dec 8, 2017 at 10:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.