I am attempting to export a range of sheets in a map series in ArcPro. I'm basing my code off ESRI's code sample 2 here https://pro.arcgis.com/en/pro-app/arcpy/mapping/mapseries-class.htm.
import arcpy, os, sys
relpath = r"S:\Tax Services\Tax Maps"
aprx = arcpy.mp.ArcGISProject(r"S:\FC GIS\GIS Projects\New Tax Maps\Tax Map DDP\Tax Map DDP - new.aprx")
l = p.listLayouts()[1]
if not l.mapSeries is None:
ms = l.mapSeries
if ms.enabled:
for pageNum in range(1, 5):
ms.currentPageNumber = pageNum
print("Exporting {0}".format(ms.pageRow.Page))
pageName = ms.pageRow.Page
l.exportToPDF(relpath + "MapSheet_{0}".format(ms.pageRow.page) + ".pdf")
However, I keep getting the following error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-2671737b67ee> in <module>()
9 for pageNum in range(1, 5):
10 ms.currentPageNumber = pageNum
---> 11 print("Exporting {0}".format(ms.pageRow.Page))
12 pageName = ms.pageRow.Page
13 l.exportToPDF(relpath + "MapSheet_{0}".format(ms.pageRow.Page) + ".pdf")
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py in pageRow(self)
2240 @property
2241 def pageRow(self):
-> 2242 return self.convert(convertArcObjectToPythonObject(getattr(self._arc_object, "pageRow")))
2243
2244
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py in convert(self, dictionary)
2236 def convert(self, dictionary):
2237 from collections import namedtuple
-> 2238 return namedtuple('pageRow', dictionary.keys())(**dictionary)
2239
2240 @property
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\collections\__init__.py in namedtuple(typename, field_names, verbose, rename, module)
399 if not name.isidentifier():
400 raise ValueError('Type names and field names must be valid '
--> 401 'identifiers: %r' % name)
402 if _iskeyword(name):
403 raise ValueError('Type names and field names cannot be a '
ValueError: Type names and field names must be valid identifiers: 'Shape.STArea()'
Any help would be appreciated!
Hello,
I started to reply to this via: https://community.esri.com/message/855395-re-exporttopng-python-for-mapseries
I don't know how to reproduce this error. Are you specifying a field to define page numbers? If so, is it numerically defined? If you set this parameter to None, does your code work?
You are also welcome to send me a project package to jbarrette@esri.com
Jeff (arcpy.mp team)
I have the field set to None, that is how I was able to fix the problem I was having similar to Elizabeth's post. I will put together a map package. thanks.
Great. A project package is better, it will contain all the map series settings. You can probably get rid of most data, leave the index layer, and save to a temporary aprx before packaging. This is to avoid a huge file size.
Jeff
Hi there GIS Coordinator,
I am going to guess that you are working with a Line/Polygon Feature Class stored in an Enterprise Geodatabase? I spoke earlier with Jeff about another customer's issues with a SQL Server Polygon Feature Class - it looks like the problem here is due to some reserved field names appearing in a dictionary used by exportToPDF. Please go ahead and contact Esri Support Services about being added to the defect log for the issue so you can closely track the status of a fix: "BUG-000123108: exportToPDF fails with "ValueError: Type names and field names must be valid identifiers: 'st_area()/'st_length()'" for SDE polygon and line feature classes."
Unfortunately, there's not a clean way to fix this in your script as the problem lies in the arcpy library itself. However, you can work around the issue by:
Hope this helps!
-Earl
I really want to thank Earl from Esri Support for being persistent and chasing this down! I did not reproduce because I tested with the project package sent to me - that was a fGDB. Earl submitted a bug and I committed it to our development queue. I prioritized this for 2.5. (it is too late for 2.4).
Jeff
Thank you for all of your work helping me on this. I greatly appreciate it.
Thank you for the suggestions. I will look into adapting my script!