Select to view content in your preferred language

ToolValidator enabled property defaults

218
0
12-28-2023 03:31 PM
Labels (1)
MErikReedAugusta
Frequent Contributor

Okay, I feel like I'm going crazy, here.

I'm trying to build a Script Tool where a Boolean checkbox input controls another parameter that accepts a Feature Class, which I remember being fairly simple in ArcMap 10.7.

I can get the tool to successfully turn the Feature Class inputs on and off after the tool is running, but I can't get them to start disabled.

Parameters 0 & 1 are the two Booleans in question.
Parameters 3 & 4 are the respective Feature Classes.

 

    def initializeParameters(self):
        # Customize parameter properties. 
        # This gets called when the tool is opened.
        
        self.params[3].enabled = False
        self.params[4].enabled = False

        return

 

 

I thought the above would be all I need to get these two parameters to start as disabled, but the tool doesn't seem to acknowledge the command.

I can confirm initializeParameters is running when the tool opens, because I threw a test dummy in there* and it worked.  (*I wrote placeholder text into the value of one of the parameters, and it successfully shows up when you open the tool)

The only place I can seem to get the tool to recognize the .enabled property right out of the gate is if I put it in __init__.  But then it fails to update properly from updateParameters, because __init__ seems to be overriding whatever I put in updateParameters.

 

I managed to figure out the below workaround, but I'm trying to figure out why I couldn't just put "self.params[3].enabled = False" into initializeParameters to set the default state and be done with it.

 

class ToolValidator:
  # Class to add custom behavior and properties to the tool and tool parameters.

    def __init__(self):
        # set self.params for use in other function
        self.params = arcpy.GetParameterInfo()
        
        # Since 0 and 1 default to False, this works for initial state.  It also avoids overriding later, because the checkbox IS the desired state.
        self.params[3].enabled = self.params[0].value
        self.params[4].enabled = self.params[1].value

    def initializeParameters(self):
        # Customize parameter properties. 
        # This gets called when the tool is opened.
        
        return

    def updateParameters(self):
        # Modify parameter values and properties.
        # This gets called each time a parameter is modified, before 
        # standard validation.
        
        if self.params[0].altered:
            self.params[3].enabled = self.params[0].value
        
        if self.params[1].altered:
            self.params[4].enabled = self.params[1].value
        
        return

    def updateMessages(self):
        # Customize messages for the parameters.
        # This gets called after standard validation.
        return

 

 

0 Kudos
0 Replies