1

I am trying to script some behaviour into the ArcGIS Toolbox validator class. Specifically, I am creating a dropdown parameter so the user can choose a predefined option and then a second parameter will update a list of items. The issue I am having is, when I change the option in the first parameter, I can get the options to change in the second parameter, but when I toggle the 'Unselect All' button in the second parameter, the items will not uncheck (they remained checked). I have a feeling it has to do with my script in the Validator.

Here are the details (see image below as well):

  1. First parameter is a string type. It is required, Input Direction, Has a default value. Multivalue = No and uses a value list so that I can have a dropdown with 3 options to choose from
  2. Second parameter is a string type. It is required. Contains Default values. Multivalue = Yes and uses a value list so that the items populated in this parameter (a list of items) can be toggled on or off.

enter image description here

So, in the Validator, my script is as follows. Can anyone see something obvious I may be missing here to get the 'Select All' and 'Unselect All' buttons to work?

import arcpy
class ToolValidator(object):
 """Class for validating a tool's parameter values and controlling
 the behavior of the tool's dialog."""
 def __init__(self):
 """Setup arcpy and the list of tool parameters."""
 self.params = arcpy.GetParameterInfo()
 def initializeParameters(self):
 """Refine the properties of a tool's parameters. This method is
 called when the tool is opened."""
 self.params[1].filter.list = [1,2,3,4]
 self.params[1].values = self.params[1].filter.list 
 return
 def updateParameters(self):
 """Modify the values and properties of parameters before internal
 validation is performed. This method is called whenever a parameter
 has been changed."""
 if self.params[0].altered == True:
 if self.params[0].value == 'Option 1': 
 self.params[1].filter.list = [1,2,3,4]
 self.params[1].values = self.params[1].filter.list
 elif self.params[0].value == 'Option 2': 
 self.params[1].filter.list = ['a', 'b', 'c']
 self.params[1].values = self.params[1].filter.list
 elif self.params[0].value == 'Option 3': 
 self.params[1].filter.list = ['dr', 'bht', 'cjjjyy']
 self.params[1].values = self.params[1].filter.list
 
 return
 def updateMessages(self):
 """Modify the messages created by internal validation for each tool
 parameter. This method is called after internal validation."""
 return
Ian Turton
84k6 gold badges93 silver badges190 bronze badges
asked Aug 19, 2020 at 21:12
1
  • @user2856 Thanks for that. That fixed it! Appreciate your time. if you're interested in submitting that as an answer, I will mark it as the correct answer and up vote. Cheers. Commented Aug 20, 2020 at 17:14

1 Answer 1

1

The "arcpy way TM" is to check if parameters[0].altered and not parameters[0].hasBeenValidated:

According to the [documentation][1]:

altered

altered is true if the value of a parameter is changed... Once a parameter has been altered, it remains altered until the user empties (blanks out) the value, in which case it returns to being unaltered.

hasBeenValidated

hasBeenValidated is false if a parameter's value has been modified by the user since the last time updateParameters and internal validate were called. Once internal validate has been called, geoprocessing automatically sets hasBeenValidated to true for every parameter.

hasBeenValidated is used to determine whether the user has changed a value since the last call to updateParameters.

So change your updateParameters to:

 def updateParameters(self):
 """Modify the values and properties of parameters before internal
 validation is performed. This method is called whenever a parameter
 has been changed."""
 if self.params[0].altered and not self.params[0].hasBeenValidated:
 etc...
answered Aug 20, 2020 at 21:30
1
  • Thanks @user2856. Great clear answer. Commented Aug 20, 2020 at 22:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.