count of maps in Arcpro project

804
5
Jump to solution
03-27-2022 03:36 PM
AmandaYoung_95
New Contributor

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)

 

 

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

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.

jcarlson_0-1648427495544.png

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}')

 

- Josh Carlson
Kendall County GIS

View solution in original post

5 Replies
DanPatterson
MVP Esteemed Contributor

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


... sort of retired...
0 Kudos
jcarlson
MVP Esteemed Contributor

Maybe that changed in a recent version?

jcarlson_0-1648431789079.png

Seems to work just fine. Not that it's a good idea, but it seems to be "legal".

- Josh Carlson
Kendall County GIS
0 Kudos
DanPatterson
MVP Esteemed Contributor

It will come back to haunt people at some point

oops.png

😉

works for some isn't a good idea


... sort of retired...
0 Kudos
jcarlson
MVP Esteemed Contributor

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.

jcarlson_0-1648427495544.png

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}')

 

- Josh Carlson
Kendall County GIS
AmandaYoung_95
New Contributor

thank you! 

0 Kudos