5

I am currently working on a python script, that i want to convert to a tool. I have managed to set it up in Arcgis as a tool, but it does not behave exactly as i want it to:

enter image description here

What i want it to do is: if the first checkmark box is not checked, the next input parameters need to be greyed out (not available for the user to specify), and if the first box is checked, parameters will be enabled, indicated by the purple arrows. and then, if the first checkmark box is checked, (which then enables the second checkmark box), it should enable the last parameter only if the 2. checkmark is checked. Basically creating a "dependency" hierarchy of some sort.

I have tested out the tool-validation, but with very little luck and was hoping someone had some more experience with customizing a tool like this! right now my validation script looks like this:

def updateParameters(self):
    if not self.params[3].hasBeenValidated:
        self.params[4].enabled = True
        self.params[5].enabled = True
        if not self.params[5].hasBeenValidated:
            self.params[6].enabled = True
        else: 
            self.params[6].enabled = False
    else:
        self.params[4].enabled = False
        self.params[5].enabled = False
return

(edit: the above script does not behave properly: when you open the tool, all input parameter fields are NOT greyed out, but when you click on the first checkmark, the last field [what is the offset above floor level?] is greyed out. then if you click the last check mark, both the last checkmark and the field [Height field] is greyed out. and if you uncheck the first checkmark, the field [Height field] and the last checkmark is un-greyed out. )

8
  • "probably" or "properly"?
    – Vince
    Commented Sep 16, 2017 at 13:32
  • sorry, i meant properly. they behave quite randomly i would say.
    – Jonas
    Commented Sep 16, 2017 at 13:44
  • Please Edit the question. We'll also want to see your diagnostic statements in the function and the diagnostic output. "Randomness" is usually misunderstanding the model of operation.
    – Vince
    Commented Sep 16, 2017 at 14:02
  • I am not entirely sure i understand what you mean with" diagnostic statements in the function and the diagnostic output" @Vince
    – Jonas
    Commented Sep 17, 2017 at 6:40
  • I suppose you looked here for reference ? : pro.arcgis.com/fr/pro-app/arcpy/geoprocessing_and_python/…
    – gisnside
    Commented Sep 17, 2017 at 7:44

1 Answer 1

6

A general introduction: to change how a tool's "interface" behaves, you can go into the validation tab of the script. this is done by right clicking on the script in the catalog window -> select properties -> change to the validation tab of the script's property window. within this tab, there are lines of default functions, that can be filled out to customize the tool. I can recommend reading https://pro.arcgis.com/fr/pro-app/arcpy/geoprocessing_and_python/customizing-script-tool-behavior.htm as @gisnside mentioned. It describes some of the possibilities for customizing the tool.

The answer specific to the question: So, after some trial and error, i found out that the Boolean input parameter (the checkmark box as i call it) has values in it: either the value is 'True' or 'False'. In the tool validator, you can ask for a parameter's value, which i didn't know was possible with the Boolean input parameter. But it is:

if self.params[3].value == True: #self.params[3] is a checkmark box/boolean parameter

This line simply tests if the checkmark box's value is true (checked) or false (unchecked). if it's false (unchecked), the other fields should be disabled, and if the box is checked, they should be enabled. the final code for the above tool now looks like this :

def updateParameters(self):  
 if self.params[3].value == True: #checking if the checkmark box is checked
    #if the box is checked (true), enable parameter 4 and 5
    self.params[4].enabled = True
    self.params[5].enabled = True
    """if parameter 5 (2. checkmark box) is enabled, 
    test if it's checked"""
    if self.params[5].value == True:
        #if parameter 5 value is checked, enable parameter 6
        self.params[6].enabled = True
    else: 
        #if its not checked, greyout/disable parameter 6
        self.params[6].enabled = False
 else:
    """this is the starting state of parameter 4,5 and 6. they are all 
    disabled/greyed out"""
    self.params[4].enabled = False
    self.params[5].enabled = False
    self.params[6].enabled = False
 return

It isn't completely trimmed, but ultimately fulfill the goal i set.

Your Answer

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

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