I'm trying to use the arcpy MapSeries Class to generate PNGs for each sheet, based on Code Example #2 here: http://pro.arcgis.com/en/pro-app/arcpy/mapping/mapseries-class.htm#C_GUID-5F34FFE0-FC62-481E-B960-A7D0554B7800.
I'd like to get the Index field name from the Map Series Index Layer to make the code flexible rather than having to hard-code in the field name in the pageRow property.
My attempts don't work, although it's easy enough to find the I can't figure out how to pass a variable into the FIELD_NAME portion of the pageRow property.
using either pageField = ms.pageNameField.name
or pageField = str(ms.pageNameField.name)
fails on: pageName = ms.pageRow.pageField
with: AttributeError: 'pageRow' object has no attribute 'pageField'
Is there any way to insert a variable into the Field Name attribute? layout.MapSeries.pageRow.FIELD_NAME
import arcpy
#get parameters
SaveLocation = arcpy.GetParameterAsText(0)
aprx = arcpy.mp.ArcGISProject("CURRENT")
l = aprx.listLayouts()[0]
if not l.mapSeries is None:
ms = l.mapSeries
if ms.enabled:
for pageNum in range(1, ms.pageCount + 1):
ms.currentPageNumber = pageNum
pageField = ms.pageNameField.name
pageName = ms.pageRow.pageField
l.exportToPNG(SaveLocation + "\\" + pageName + ".png")