I've adapted the following script to export each page of a map series to individual PDF files but it exports the entire map series 50 times (number of pages) and updates each export name with the name of each page title.
The original script exports each page to PNG file ( MapSeries example 2)
aprx = arcpy.mp.ArcGISProject(ProProject)
try:
msLayout = aprx.listLayouts('Neighborhoods MapBook')[0] ## the number in brackets is the number in the layout
print ('Layout {}'.format(msLayout.name))
if not msLayout.mapSeries is None:
ms = msLayout.mapSeries
ms.refresh()
if ms.enabled:
for pageNum in range(1, ms.pageCount + 1):
ms.currentPageNumber = pageNum
pageName = ms.pageRow.NHNAME
ms.exportToPDF(os.path.join(OutFolder, f"NeighborhoodsMapBook_{ms.pageRow.NHNAME}.pdf"))
print(ms.pageRow.NHNAME + ' exported')
except:
message = arcpy.GetMessages()
Solved! Go to Solution.
MapSeries.exportToPdf() activates each page of the series and exports them into the same pdf. You do that process for each page.
What you want to do is activate each page, then export the layout.
aprx = arcpy.mp.ArcGISProject(ProProject)
try:
msLayout = aprx.listLayouts('Neighborhoods MapBook')[0] ## the number in brackets is the number in the layout
print ('Layout {}'.format(msLayout.name))
if not msLayout.mapSeries is None:
ms = msLayout.mapSeries
ms.refresh()
if ms.enabled:
for pageNum in range(1, ms.pageCount + 1):
ms.currentPageNumber = pageNum
pageName = ms.pageRow.NHNAME
msLayout.exportToPDF(os.path.join(OutFolder, f"NeighborhoodsMapBook_{ms.pageRow.NHNAME}.pdf"))
print(ms.pageRow.NHNAME + ' exported')
except:
message = arcpy.GetMessages()
MapSeries.exportToPdf() activates each page of the series and exports them into the same pdf. You do that process for each page.
What you want to do is activate each page, then export the layout.
aprx = arcpy.mp.ArcGISProject(ProProject)
try:
msLayout = aprx.listLayouts('Neighborhoods MapBook')[0] ## the number in brackets is the number in the layout
print ('Layout {}'.format(msLayout.name))
if not msLayout.mapSeries is None:
ms = msLayout.mapSeries
ms.refresh()
if ms.enabled:
for pageNum in range(1, ms.pageCount + 1):
ms.currentPageNumber = pageNum
pageName = ms.pageRow.NHNAME
msLayout.exportToPDF(os.path.join(OutFolder, f"NeighborhoodsMapBook_{ms.pageRow.NHNAME}.pdf"))
print(ms.pageRow.NHNAME + ' exported')
except:
message = arcpy.GetMessages()
Thanks Johannes!!
The script now exports each page but it stops at page 25
Do you have any idea why it's doing that?