Hey guys,
I am dealing with unable to use postExecute method within Python Toolbox or atbx toolbox.
class Tool(object
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Tool"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
param1 = arcpy.Parameter(
displayName="Dos",
name="param1",
datatype="DEFeatureClass",
parameterType="Required",
direction="Input")
param2 = arcpy.Parameter(
displayName="Output Features",
name="out_features",
datatype="GPFeatureLayer",
parameterType="Derived",
direction="Output")
return [param1, param2]
def execute(self, parameters, messages):
"""The source code of the tool."""
param1 = parameters[0].valueAsText
gdb = "gdb_path"
out = f"{gdb}/layer2"
arcpy.CopyFeatures_management(param1, out)
arcpy.SetParameter(1, out)
arcpy.AddMessage("Tool has finished executing222")
return
def postExecute(self, parameters, messages):
"""This method takes place after outputs are processed and
added to the display."""
arcpy.AddMessage("Tool has finished executing!!!!!!!!!!!!!!!!!!!!")
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
I've used example from documentation, has anyone had any success with using postExecute?
Do I need to execute it someway?
Code is basic, just for testing purpose.
regards,
Yanu
What does the toolbox look like? That is where you execute the tool from within your project's toolbox
Toolbox is like this:
import arcpy
import os
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Toolbox"
self.alias = "toolbox"
# List of tool classes associated with this toolbox
self.tools = [Tool]
Default, postExecute is also from documentation.
They suggested using postExecute:
here Bug with symbology
Yes that is the code, but have you added the toolbox to your project and tried to execute it?
Catalog, Project tab, Toolboxes with my toolbox which has a tool with a toolset and a tool shown
which you can launch and run to test whether it works or check its properties
for tool validation... (postExecute is commented out here since none is needed)
Thank you for your reply Dan.
Yes, I've added this Python Toolbox to project.
I tried also setting up ATBX from scartch and testing if postExecute will run.
Nothing happens...
postExecute is new. Are you using ArcGIS Pro 3.x?
I know, I am using 3.1.1.
I've checked patch notes, 0 bugs...
Which leaves the thread you posted BUG-000155515 for ArcGIS Pro (esri.com)
so I would open an Issue with Tech Support so they can investigate why it isn't working.... I don't use postExecute in my toolboxes
Hi Yanu, Dan and Luke
I'm using ArcGIS Pro 3.3 and have same problems with "postExecute" routine.
It seems do nothing.
Any news from the BUGS?
BUG-000155515 for ArcGIS Pro (esri.com) still lists the status as "known limitation"
so contacting Tech Support would be your best option