The postExecute method is an optional validation method that runs after a tool's processing is complete. The method is called after a tool's script file is complete and the 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):
try:
project = arcpy.mp.ArcGISProject('CURRENT')
active_map = project.activeMap
if active_map:
out_layer = active_map.listLayers(os.path.basename(self.params[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
Remarque :
The Apply Symbology By Layer tool is not supported in postExecute. Use the arcpy.mp module's Symbology class instead.
Rubriques connexes
Vous avez un commentaire à formuler concernant cette rubrique ?