Select to view content in your preferred language

Issue Exporting Map Series as Jpegs Using Arcpy.mp Module in ArcGIS Pro 2.8

4098
5
Jump to solution
06-07-2021 09:18 AM
Labels (2)
JesseClark
Occasional Contributor

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

 

 

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
JeffBarrette
Esri Regular Contributor

Hi Jesse,

We just had a support issue created where if a label class has a PYTHON expression then export via arcpy.mp to PDF causes the script to hang.  Turning of labels, as you discovered, help but so does does changing the expression engine from Python to Arcade. Can you please confirm?  This was a new bug for 2.8. If its the same thing, we prioritized it as a 2.8 patch candidate.

 

Jeff - Layout and arcpy.mp teams.

View solution in original post

0 Kudos
5 Replies
JeffBarrette
Esri Regular Contributor

Jesse, I just ran your exact code (plus I added the Toolbox class to make it complete) and it worked for me on Pro 2.8 and Pro 2.7.  Are there any other special Map Series settings?  For example, are you setting page numbers in any way to either have a starting number or using a page number field?

Jeff - arcpy.mp and Layout teams

 

0 Kudos
JesseClark
Occasional Contributor

Thanks for running the code on your end Jeff. The confirmation that it worked was useful. I'm including a clip of the map series options window used in the layout. Nothing stands out, except the sort field... maybe. I did just run the tool on a layout in a different ArcGIS Pro project file with success, so I'll circle back and have a closer look at my map series settings in the project having issues. I'll probably export as a PDF series using the regular export layout function in Pro and see if I can get it to cough up an error to work with. 

 Map Series Options.PNG

0 Kudos
JesseClark
Occasional Contributor

Further inspection suggests the export issue has to do with at least one of several label classes created when I imported the layout from an existing ArcMap document. I discovered the map series exports fine with the python code when all label classes are disabled. 

0 Kudos
JeffBarrette
Esri Regular Contributor

Hi Jesse,

We just had a support issue created where if a label class has a PYTHON expression then export via arcpy.mp to PDF causes the script to hang.  Turning of labels, as you discovered, help but so does does changing the expression engine from Python to Arcade. Can you please confirm?  This was a new bug for 2.8. If its the same thing, we prioritized it as a 2.8 patch candidate.

 

Jeff - Layout and arcpy.mp teams.

0 Kudos
JesseClark
Occasional Contributor

Hi Jeff, can confirm. I'm actually in the process of converting my python label expressions to Arcade syntax. 

0 Kudos