Select to view content in your preferred language

Export a map series to pdf with Python

4233
6
02-25-2022 12:20 PM
KeithAddison1
Frequent Contributor

Pro 2.9.1 - I have a mapbook that now crashes when you try to export anything, it either hangs forever, as in 48 hours later still grinding away with no progress, or sometimes it crashes to the desktop.  Same results if done with the series export as with the standard single sheet export.  So I need to use Python to export anything now.  What's the simplest way to export a map series via the Python window?

0 Kudos
6 Replies
DanPatterson
MVP Esteemed Contributor

see if any of this applies

Solved: ArcGIS Pro 2.9 Map Series Export Crash - Esri Community


... sort of retired...
0 Kudos
AubriKinghorn
Esri Regular Contributor

Hi, 

There was a known crash with exporting when there was a blank text element on the layout, as Dan mentioned above. This was addressed in 2.9.1, which it sounds like you are using. If you can, I highly recommend reaching out to tech support so they can get this bug into the hands of the development team to be fixed. This is a definite problem.

 

In the meantime, here is a simple python script that exports the first map series in the project to a single PDF file:

 

##Export to PDF
aprx = arcpy.mp.ArcGISProject("CURRENT")
l = aprx.listLayouts()[0]
if not l.mapSeries is None:
    ms = l.mapSeries
    ms.exportToPDF(f"C:\Temp\{l.name}.pdf")
print("Done")

 

 

You can learn more about the methods and customizations in the documentation here: https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/mapseries-class.htm

 

I hope this helps. 

Cheers,

Aubri 

Cheers,
Aubri
KeithAddison1
Frequent Contributor

Thanks for the response.  When I run this I get an error saying "name 'lyt' is not defined"  Which module do I need to import for it?  I've already got import arcpy, os, sys as part of my code.

0 Kudos
AubriKinghorn
Esri Regular Contributor

My apologies, that was a typo in my code. It should be ms = l.mapSeries. I've edited the comment above to fix the code. 

Cheers,
Aubri
0 Kudos
KeithAddison1
Frequent Contributor

Thanks!

0 Kudos
AbigailMcHenry
New Contributor

Thank you @AubriKinghorn this simple bit of code will save me so much time in exporting map series! I modified it to export all my map series within my project using this: 

	import arcpy,os
	
	##Export to PDF
	aprx = arcpy.mp.ArcGISProject("CURRENT")
	for l in aprx.listLayouts():
	    if not l.mapSeries is None:
	        ms = l.mapSeries
	        ms.exportToPDF(f"C:\Temp\{l.name}.pdf")
	print("Done")