Postprocessing validation in a Python toolbox

The postExecute method is an optional validation method that runs after a tool's processing is complete. The method is called after a Python toolbox tool's execute method is complete and outputs are added to the Contents pane for the active map. This method allows you to use the arcpy.mp module to query and change the display of outputs.

The postExecute code identifies the layer from the active map and uses a SimpleRenderer value to change the symbology for each point to an airport symbol. The code assumes that the tool's second parameter is an output point feature class.

def postExecute(self, parameters):
    
    try:
        project = arcpy.mp.ArcGISProject('CURRENT')
        active_map = project.activeMap
        
        if active_map:
            out_layer = active_map.listLayers(os.path.basename(parameters[1].valueAsText))[0]
            
            symbology = out_layer.symbology
            symbology.updateRenderer('SimpleRenderer')
            symbology.renderer.symbol.applySymbolFromGallery('Airport')
            symbology.renderer.symbol.size = 12
            out_layer.symbology = symbology
            
    except Exception:
        pass

    return
Hinweis:

The Apply Symbology By Layer tool is not supported in postExecute. Use the arcpy.mp module's Symbology class instead.

Verwandte Themen