Hello, I have a arcpro project and inside the projects, i have 2 maps and and each map 3 layers. I want to print the number of maps and and number of layers within each maps. i have this so far and i am getting errors. any tips ?
import arcpy
aprx_path = "C:/.colorado.aprx"
aprx = arcpy.mp.ArcGISProject(aprx_path)
maps = aprx.listMaps()
for m in maps:
print(m.count)
Solved! Go to Solution.
The listMaps() method gives you a list. Simply call len(maps) to get the count. The code you have written is attempting to access a count property of each individual map and print it, but no such property exists, at least in my maps.
To get your layer counts per map, you just do the same thing, but with the output of the map's listLayers() method.
print(f'{len(aprx.listMaps())} maps in project.')
for m in aprx.listMaps():
print(f'{len(m.listLayers())} layers in {m.name}')
The error message would help.
"C:/.colorado.aprx"
will fail, if that is the path since an aprx can't exist in the root directory nor begin with punctuation.
Also your formatting could use line numbers.
Code formatting ... the Community Version - Esri Community
Maybe that changed in a recent version?
Seems to work just fine. Not that it's a good idea, but it seems to be "legal".
It will come back to haunt people at some point
😉
works for some isn't a good idea
The listMaps() method gives you a list. Simply call len(maps) to get the count. The code you have written is attempting to access a count property of each individual map and print it, but no such property exists, at least in my maps.
To get your layer counts per map, you just do the same thing, but with the output of the map's listLayers() method.
print(f'{len(aprx.listMaps())} maps in project.')
for m in aprx.listMaps():
print(f'{len(m.listLayers())} layers in {m.name}')
thank you!