Export Map Series to JPEG arcpy - error exporting a select range

1035
2
Jump to solution
06-08-2022 10:10 AM
RobinLatour
New Contributor II

I have this script to export a Map Series to JPEG, based on ESRI's Map Series code sample #2, and it works well except when I try to export just a range of pages, not the whole set. 

import arcpy, os, sys

p = arcpy.mp.ArcGISProject(r"G:\2xxx Projects\EA\2xxx-182 Oxford Road\ArcPro_Workspace\ArcPro_Workspace.aprx")
l = p.listLayouts("Stg1_results")[0]
print(l)
print(l.mapSeries)
if not l.mapSeries is None:
ms = l.mapSeries
print(ms.enabled)
if ms.enabled:
for pageNum in range(1, ms.pageCount + 1):
print("Exporting {0}".format(ms.pageRow.PageNumber))
pageName = ms.pageRow.PageNumber
l.exportToJPEG(os.path.join(r"Y:\2xxx Projects\EA\2xxx-182 Oxford Road\Output", "Stage 1 REV", f"S{ms.pageRow.PageNumber}"))

 

I have tried modifying the pageNum in range to show the pages I want (ex., pageNum in range(21,24,26,40) but I get a syntax error or invalid page numbers. Can anyone suggest how to modify this so I can extract just the pages I need?
Thanks. 

0 Kudos
1 Solution

Accepted Solutions
RobinLatour
New Contributor II

Ok - i posted this and then solved it myself! Figures.
So if anyone is interested, this worked! Changes in lines 11-12 area, regarding pageNumbers

import arcpy, os,sys

p = arcpy.mp.ArcGISProject(r"#rel path of aprx#")
l = p.listLayouts("#layout with map series#")[0]
print(l)
print(l.mapSeries)
if not l.mapSeries is None:
  ms = l.mapSeries
  print(ms.enabled)
  if ms.enabled:
      pageNumbers = [#page range with commas#]
for pageNum in pageNumbers:
           ms.currentPageNumber = pageNum
           print("Exporting {0}".format(ms.pageRow.PageNumber))
           pageName = ms.pageRow.PageNumber
           l.exportToJPEG(os.path.join(r"#export location#", "#folder#", f"S{ms.pageRow.PageNumber}"))

View solution in original post

0 Kudos
2 Replies
RobinLatour
New Contributor II

Ok - i posted this and then solved it myself! Figures.
So if anyone is interested, this worked! Changes in lines 11-12 area, regarding pageNumbers

import arcpy, os,sys

p = arcpy.mp.ArcGISProject(r"#rel path of aprx#")
l = p.listLayouts("#layout with map series#")[0]
print(l)
print(l.mapSeries)
if not l.mapSeries is None:
  ms = l.mapSeries
  print(ms.enabled)
  if ms.enabled:
      pageNumbers = [#page range with commas#]
for pageNum in pageNumbers:
           ms.currentPageNumber = pageNum
           print("Exporting {0}".format(ms.pageRow.PageNumber))
           pageName = ms.pageRow.PageNumber
           l.exportToJPEG(os.path.join(r"#export location#", "#folder#", f"S{ms.pageRow.PageNumber}"))

0 Kudos
AlanHobson
New Contributor

Doe this keep the georeferencing? my jpegs had no coordinates, is there a way to keep that?

0 Kudos