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?
-
1Where in your code are you calling updateParameters()?artwork21– artwork212018年02月08日 13:41:32 +00:00Commented Feb 8, 2018 at 13:41
-
I don´t call updateParameters() anywhere. I meant that the code in the updateParameters function was not working. I don´t know the reason. If the second parameter was an ordinary non-composite data type, the same code works.jonlew– jonlew2018年02月08日 13:47:14 +00:00Commented Feb 8, 2018 at 13:47
-
For a Python Toolbox question I think we need to see all the code for a test toolbox that illustrates what you have tried and where you are stuck. At the moment it seems like you have copy/pasted two functions from your actual code.PolyGeo– PolyGeo ♦2018年02月08日 22:56:05 +00:00Commented Feb 8, 2018 at 22:56
-
Yes I copy/pasted it as the rest of the toolbox probably has no influence on validating process. I edited the question and provided full tool´s script.jonlew– jonlew2018年02月09日 12:27:23 +00:00Commented Feb 9, 2018 at 12:27
-
1Those parameters cannot be enabled or disabled if you do not call the updateParameters() function.artwork21– artwork212018年02月09日 13:36:51 +00:00Commented Feb 9, 2018 at 13:36
1 Answer 1
I made a few alterations to your code and it does change from enabled to disabled on my machine running ArcGIS 10.4.
def getParameterInfo(self):
param0 = arcpy.Parameter(
displayName="Tick",
name="a",
datatype="GPBoolean",
parameterType="Optional",
direction="Input")
param0.value = False
param1 = arcpy.Parameter(
displayName="Output location",
name="b",
datatype=["DEFolder", "DEFeatureDataset"],
parameterType="Optional",
direction="Input")
param1.enabled=False
params = [param0, param1]
return params
def updateParameters(self, parameters):
if parameters[0].altered:
if parameters[0].value:
parameters[1].enabled = 0
else:
parameters[1].enabled = 1
return
The biggest change was to set the checkbox value to false, and the enabled parameter to false when the parameters get set. I also added to see if param0 was altered, but this doesn't really make a difference.
-
Unfortunately not working on ArcGIS 10.1. I copied your code and no success. It might be a bug in earlier versions of ArcGIS as I have found several of them. I´m marking your answer as accepted, thanks.jonlew– jonlew2018年02月12日 15:42:42 +00:00Commented Feb 12, 2018 at 15:42
-
If you are using 10.1, try it without the keywords maybe. resources.arcgis.com/en/help/main/10.1/index.html#//… "Use of keywords for parameter data types was introduced at 10.1 service pack 1. Parameter descriptions can still be used but are not localized and cannot be used for different locales."dslamb– dslamb2018年02月12日 16:03:51 +00:00Commented Feb 12, 2018 at 16:03
-
I am using 10.1 SP1 (I may have forgotten to mention it) to be able to work with data access module. To summarize the topic - actually I am not able to disable a composite data type parameter. But I can live with it...jonlew– jonlew2018年02月12日 20:10:18 +00:00Commented Feb 12, 2018 at 20:10
Explore related questions
See similar questions with these tags.