I'm trying to export my ArcGIS Pro map series to PNG. I'm using the MapSeries example code #2 from Esri (http://pro.arcgis.com/en/pro-app/arcpy/mapping/mapseries-class.htm ). I keep getting an Invalid page number error.
Any help is much appreciated!!
See below code and error:
Code:
import arcpy, os, sys
relpath = "Z:\\41708.02 VAGuidehouse - MAHSO Call 1\\300TIG\\315Maps\\Maps_DDF"
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
 print("layoutName{0}".format(ms.pageRow.Market))
 pageName = ms.pageRow.Market
 l.exportToPNG(relpath + "\\PNG_Test\\S7_MKTOVW_{0}".format(ms.pageRow.Market) + ".png")
Error:
Traceback (most recent call last):
 File "<string>", line 10, in <module>
 File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\arcobjects\_base.py", line 109, in _set
 return setattr(self._arc_object, attr_name, cval(val))
ValueError: Invalid page number '1'.
Jeff:
I'm not sure if you're responding to me or Elizabeth. I created a similiar post to her's here https://community.esri.com/thread/234564-exportingtopdf-python-for-map-series
Thanks,
Sorry, I confused the posts/names. Same intention to help. I will look at your other post.
I'm late to the party but this thread was helpful to me, so thanks Elizabeth for making the post. I modified your script ever so slightly and it ran just fine for me. Here is the snippit that I used:
import arcpy, os, sys
relpath = r'''F:\0 - Ranking All Unknowns\insetmaps'''
aprx = arcpy.mp.ArcGISProject("CURRENT")
for item in aprx.listLayouts():
 itemname = item.name
 print(itemname)
l = aprx.listLayouts()[5]
print(l.name)
ms = l.mapSeries
for pageNum in range(1, ms.pageCount + 1):
 ms.currentPageNumber = pageNum
 pagename = ms.pageRow.Invnum
 print("{}".format(pagename))
 filename = pagename + ".png"
 print(filename)
 endlocation = os.path.join(relpath, filename)
 print(endlocation)
 l.exportToPNG(endlocation)