Using a variable to get the pageRow field value in a Map Series?

12-16-2020 10:12 AM
New Contributor II


In the snippet below you can see that I am calling  ms.pageRow.PageName to get the value for the field named "PageName" in my Index Layer. This is how all the sample code I have found does it. But, how can you do this using a string variable for the field name? For instance you want to pass in the field name as an argument to the script. I have tried getValue("PageName") like you see in the SDK documentation, but that does not work. Any ideas?

if not lyt.mapSeries is None:
  ms = lyt.mapSeries

if ms.enabled:
  for pageNum in range(1, ms.pageCount + 1):
    ms.currentPageNumber = pageNum
    page = ms.pageRow.PageName # <-- ??How to use a variable field name here??
    print(" - {0}".format(output_path + f"file_{page}.pdf"))
    lyt.exportToPDF(output_path + f"file{page}.pdf", resolution = 300)


0 Kudos
1 Reply
New Contributor

Unfortunately, the ESRI docs are wrong.  MapSeries.pageRow doesn't return a Row object, but a pageRow object, which does not have the getValue method.

You can use Python's getattr method to return the value instead.

page = getattr(ms.pageRow,
0 Kudos