I’m tasked with modifying an existing PYT toolbox…a format I’m not familiar with.
I do have pretty good experience with non-PYT tools, and with configuring their ToolValidator code.
What I’d like to do is modify the PYT so that it will open with one of the parameters in a disabled state, but I’m not sure if the code format is the same as in a ToolValidator class…like params[5].enabled = False…and I’m not sure where in the PYT to place that code.
Can anyone offer advice, please? Thank you!
Solved! Go to Solution.
You can change the parameter states and values in getParameterInfo() and updateParameters(). You can change parameter warnings and errors in updateMessages().
In your case, you would do something like this:
class SomeTool:
label = "SomeTool"
def getParameterInfo(self):
# define the parameters
parameters = [
arcpy.Parameter(...),
arcpy.Parameter(...),
arcpy.Parameter(...),
]
# change default values, filters, and visibility
parameters[0].filter.list = [1, 2, 3]
parameters[1].enabled = False
parameters[2].value = "default"
return parameters
def updateParameters(self, parameters):
if parameters[0].value == 1:
parameters[1].enabled = True
else:
parameters[1].enabled = False
def updateMessages(self, parameters):
parameters[0].setWarningMessage("You have been warned")
For more, here'S the official doc: https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/parameter.htm
You can change the parameter states and values in getParameterInfo() and updateParameters(). You can change parameter warnings and errors in updateMessages().
In your case, you would do something like this:
class SomeTool:
label = "SomeTool"
def getParameterInfo(self):
# define the parameters
parameters = [
arcpy.Parameter(...),
arcpy.Parameter(...),
arcpy.Parameter(...),
]
# change default values, filters, and visibility
parameters[0].filter.list = [1, 2, 3]
parameters[1].enabled = False
parameters[2].value = "default"
return parameters
def updateParameters(self, parameters):
if parameters[0].value == 1:
parameters[1].enabled = True
else:
parameters[1].enabled = False
def updateMessages(self, parameters):
parameters[0].setWarningMessage("You have been warned")
For more, here'S the official doc: https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/parameter.htm
Perfect! Thank you.
I'd been trying to use the params[5].enabled = False format from ToolValidator instead of parameters[5].enabled = False.