I have a simple tool with two parameters:
- a boolean (just to tick or untick it)
- a composite data (where I can choose an output location - either a folder or a feature dataset).
I am unable to access this composite data type parameter correctly. I want the script to work like this - if I tick the boolean, I´d like both choices of the composite parameter to be disabled (=grey). If I untick it, I want the second parameter to be enabled.
The code looks like this:
class Tool(object):
def __init__(self):
self.label = "Tool"
self.description = "Prints output location"
self.canRunInBackground = False
def getParameterInfo(self):
param0 = parameter("a", "Tick", "GPBoolean", "Optional")
param1 = parameter("b", "Output location", ["DEFolder", "DEFeatureDataset"], "Optional")
params = [param0, param1]
return params
def updateParameters(self, parameters):
if parameters[0].value:
parameters[1].enabled = 0
else:
parameters[1].enabled = 1
return
def execute(self, parameters, messages):
a = parameters[0].value
b = parameters[1].valueAsText
if a:
arcpy.AddMessage("A is ticked.")
else:
arcpy.AddMessage("B is chosen instead:" + b)
del a
del b
return
The code in updateParameters is not working as expected, whether I have the boolean ticked or not, the second parameter is still enabled.
I tried parameters[1][0].enabled = 0 but validation says that the object is not subscriptable. Then I tried changing the second (composite data type) parameter to a non-composite data type parameter and it worked. But when it is a composite data type parameter, the parameters[1].enabled = 0 within updateParameters function does not work.
How to make the second parameter disabled when the first parameter is ticked?
