Can anyone in the ArcGIS Pro community help me understand why this tool I created in a python toolbox for exporting a page series as Jpeg files hangs up on map 1 of 37, but does not produce an error message? Map 1 is exported as a 4 kb jpg file when viewed in Windows Explorer, but cannot be opened. Meanwhile the tool continues running, without exporting additional files. Any guidance is appreciated - thank you!
class exportPageSeriesAsJPG(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Export Page Series as JPGs"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
param0 = arcpy.Parameter(name = "targetProject", \
displayName = "Target Project", \
datatype = "DEFile", \
parameterType = "Required",\
direction = "Input")
param0.filter.list = ['aprx']
param1 = arcpy.Parameter(name = "targetFolder", \
displayName = "Target Folder", \
datatype = "DEFolder", \
parameterType = "Required",\
direction = "Input")
param2 = arcpy.Parameter(name = "targetLayout", \
displayName = "Layout", \
datatype = "GPString", \
parameterType = "Required",\
direction = "Input")
param2.filter.type = "ValueList"
param2.filter.list = []
params = [param0,param1,param2]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
if parameters[0].value:
project = arcpy.mp.ArcGISProject(parameters[0].value)
parameters[2].filter.list = sorted([layout.name for layout in project.listLayouts()])
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
import os
filePath = os.path.abspath(parameters[1].ValueAsText)
project = arcpy.mp.ArcGISProject(parameters[0].value)
layout = project.listLayouts(parameters[2].value)[0]
if layout.mapSeries.enabled:
for pageNum in range(1, layout.mapSeries.pageCount + 1):
layout.mapSeries.currentPageNumber = pageNum
arcpy.AddMessage("Exporting {0}".format(layout.mapSeries.pageRow.SITE_ID))
layout.exportToJPEG(os.path.join(filePath, f"{layout.mapSeries.pageRow.SITE_ID}.jpg"),300)
return