Select to view content in your preferred language

Extract info about scale from specific map frame in every map in Map Series

689
2
03-17-2023 08:14 AM
HannaBarysevich
New Contributor

Hi! I'm trying to run python script in ArcGis Pro. 

I need to extract information about scale from specific map frame (there are few of them in the layout) in every map in Map Series. I am a new user of Arcgis Pro and python and I stuck 😞 

The script I prepared prints out scale info, but it prints always the same value (= the value of scale for map, which is now displayed). 

I will be very grateful if someone help me. 

 

"""

import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
l = aprx.listLayouts("nameOfLayout")[0]

if not l.mapSeries is None:
    ms = l.mapSeries
    if ms.enabled:
        pageName = ms.pageRow.OBJECTID
        for pageNum in range(1, ms.pageCount + 1😞
            ms.currentPageNumber = pageNum
            mf_main = l.listElements("MapFrame_Element", "Main Map Frame")[0] ## for "Main Map Frame" I need values from all the maps in map series 
            scale = mf_main.camera.scale
            print(pageNum)
            print(scale)

 

"""

0 Kudos
2 Replies
HannesZiegler
Esri Contributor

There could be a subtle logic error hiding in your code. I'm not familiar with arcpy.mp, but it looks like you are always grabbing the same (the first in the series) map frame and getting the scale from it, so the scale printed will always be the one of the first map frame in the series. Try confirming if this is the case with some debug print statements and if it is the case, make sure you grab the scale from each frame rather than just the first frame.

Maybe something like this:

 

# Loop through each map frame in the layout
    for mf in layout.listElements("MAPFRAME_ELEMENT"):
        if mf.name == "Main Map Frame":
            scale = mf.camera.scale

 

Hope that helps get you unstuck!

0 Kudos
WCall
by
New Contributor

Hello,

I'm not sure if you ever got an answer, but I had the same question and came up with this:

for lyt in aprx.listLayouts():
if not lyt.mapSeries is None:
#print(lyt.name)
ms = lyt.mapSeries
if ms.enabled: # checks to see if the ms is a map series
for pageNum in range(1, ms.pageCount + 1): # goes through all pages (no matter how many)
ms.currentPageNumber = pageNum # sets the "current" page with the pageCount, which is the pageNum in the iteration
print((ms.pageRow.Name + " " + str(pageNum))) # prints the page name (from the index layer) and the page number

# now goes back to the layout
mf = lyt.listElements("MAPFRAME_ELEMENT", "*Main*")[0] # the map for the series has the word "Main" in it
print(str(mf.camera.scale))