I've written an arcpy script tool to automate exporting a map series to a set of image files (one image file for each page of the map series).
Each image has the correct features displayed, for those layers that have a page query for the map series. So I know that changing the currentPageNumber
of the map series is working, at least partially. It even progresses to the next page in ArcGIS Pro's table of Contents when showing the map series pages in the Contents page. The map title (which includes map-series-based elements) also updates correctly.
However, each image also has the same extent (the extent of the first page of the map series). There should be a different extent for each page (and for each image). The extent changes correctly when I change pages in ArcGIS Pro, but it does not change when running the tool. The extent in ArcGIS Pro's layout view also does not change when the tool runs (but as described above, it does change the page in the Contents pane, and changes the map page title).
The relevant portion of the tools script is as follows:
for pageNum in range(1, series.pageCount + 1):
series.currentPageNumber = pageNum
#series.refresh()
pageName = series.pageRow[0]
arcpy.SetProgressorPosition(pageNum)
userMsg("Exporting page {} of {} ({})...".format(pageNum, series.pageCount, pageName))
filepath = os.path.join(outFolder, f"{filename} - {pageName}.{format.lower()}")
if format = "JPEG":
layout.exportToJPEG(filepath, resolution, jpeg_quality=jpegQuality)
else:
layout.exportToPNG(filepath, resolution)
How can I get this to show the correct extent for each exported image?
UPDATE:
Adding a mapSeries refresh()
immediately after each update to the currentPageNumer
(ie, after each page change) fixes the problem MOST of the time (I've added this to the code above, commented out). But the problem still occurs randomly for approximately 3 of every 20 pages, even with the per-page refresh()
. When using the refresh()
(uncommented) it is random which pages have the problem. Without refresh()
(commented out), ALL pages have the same extent.