I'm using ArcPy to iterate through maps in a Pro project. I have only one map in the Project called "Mines".
However, when I use listMaps to iterate through the maps in the aprx, it returns two values called "Mines". Any ideas why this is? Furthermore, if I list all the layers in each "Mines" map, the layers are slightly different. The first Mines map in the list contains layers that I actually deleted from the Pro Project, but the second one doesn't have this problem. And yes, I saved the Pro Project.
Here's the code:
aprx = arcpy.mp.ArcGISProject(path_to_project)
for mp in aprx.listMaps("Mines"):
print(mp.name)
Really strange. Someone tell me I'm not in the Twilight Zone.
Solved! Go to Solution.
Not sure why exactly this is happening, but I reckon this might have something to do with the fact that the Pro Project was created from a map package (.mpk) file, instead of adding layers to a blank Project's map. Regardless of why it happens, this is how I solved it.
In a Python Notebook from within the Pro Project, I looped through the list of maps in the current Project and renamed the maps that are not active maps to have names other than "Mines". This allows my script that I wrote to access the single map named "Mines" which is what I wanted. Here's the code:
aprx = arcpy.mp.ArcGISProject("CURRENT")
for mp in aprx.listMaps():
if mp != aprx.activeMap:
mp.name = "OTHER"
Have you tried using 'CURRENT' instead of the variable/path to your project? Obviously this won't work when the app isn't open, but it might point to where the issue is occurring.
This is good advice. Instead of working from VS Code, I opened up the Pro Project's Python IDE. I then renamed the other nonactive maps to something else, so that I can access the true "Mines" map from the Project.
works for me outside of Pro
import arcpy
pth = r"C:\arcpro_npg\npg\Project_npg\npGeom.aprx"
aprx = arcpy.mp.ArcGISProject(pth)
# -- no limits
for i, m in enumerate(aprx.listMaps()):
print(f"{i} : {m.name}")
0 : npgeom tests
1 : Odd_concave
... snip
17 : Map1
18 : Dissolve
19 : sq tests
# -- wildcard limit
pth = r"C:\arcpro_npg\npg\Project_npg\npGeom.aprx"
for i, m in enumerate(aprx.listMaps("Map1")):
print(f"{i} : {m.name}")
0 : Map1
# -- another one
for i, m in enumerate(aprx.listMaps("Map*")):
print(f"{i} : {m.name}")
0 : Map
1 : Map1
First I would check the catalog pane to see what you have under "maps"' some map can exists without an existing tab.
By best guess is that your aprx is corrupted. You should be able to copy the maps you need to a clean aprx.
Have fun
No other maps exist in catalog pane. I think the issue is somehow connected to the fact that this Pro project was created from a map package file. Somehow that created duplicate maps that I can't see listed in the tabs or catalog pane.
Not sure why exactly this is happening, but I reckon this might have something to do with the fact that the Pro Project was created from a map package (.mpk) file, instead of adding layers to a blank Project's map. Regardless of why it happens, this is how I solved it.
In a Python Notebook from within the Pro Project, I looped through the list of maps in the current Project and renamed the maps that are not active maps to have names other than "Mines". This allows my script that I wrote to access the single map named "Mines" which is what I wanted. Here's the code:
aprx = arcpy.mp.ArcGISProject("CURRENT")
for mp in aprx.listMaps():
if mp != aprx.activeMap:
mp.name = "OTHER"