0

I have a simple tool with two parameters:

  1. a boolean (just to tick or untick it)
  2. 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.

How it should work

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?

  • 1
    Where in your code are you calling updateParameters()? – artwork21 Feb 8 '18 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 Feb 8 '18 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 Feb 8 '18 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 Feb 9 '18 at 12:27
  • 1
    Those parameters cannot be enabled or disabled if you do not call the updateParameters() function. – artwork21 Feb 9 '18 at 13:36
0

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.

|improve this answer|||||
  • 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 Feb 12 '18 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 Feb 12 '18 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 Feb 12 '18 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.