Select to view content in your preferred language

Disable PYT toolbox parameter

694
2
Jump to solution
01-11-2023 07:41 PM
CarlBeyerhelm
Frequent Contributor

I’m tasked with modifying an existing PYT toolbox…a format I’m not familiar with.

I do have pretty good experience with non-PYT tools, and with configuring their ToolValidator code.

What I’d like to do is modify the PYT so that it will open with one of the parameters in a disabled state, but I’m not sure if the code format is the same as in a ToolValidator class…like params[5].enabled = False…and I’m not sure where in the PYT to place that code.

Can anyone offer advice, please?  Thank you!

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

You can change the parameter states and values in getParameterInfo() and updateParameters(). You can change parameter warnings and errors in updateMessages().

In your case, you would do something like this:

 

 

class SomeTool:
    label = "SomeTool"

    def getParameterInfo(self):
        # define the parameters
        parameters = [
            arcpy.Parameter(...),
            arcpy.Parameter(...),
            arcpy.Parameter(...),
            ]
        # change default values, filters, and visibility
        parameters[0].filter.list = [1, 2, 3]
        parameters[1].enabled = False
        parameters[2].value = "default"
        return parameters

    def updateParameters(self, parameters):
        if parameters[0].value == 1:
            parameters[1].enabled = True
        else:
            parameters[1].enabled = False

    def updateMessages(self, parameters):
        parameters[0].setWarningMessage("You have been warned")

 

 

 

For more, here'S the official doc: https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/parameter.htm 


Have a great day!
Johannes

View solution in original post

0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor

You can change the parameter states and values in getParameterInfo() and updateParameters(). You can change parameter warnings and errors in updateMessages().

In your case, you would do something like this:

 

 

class SomeTool:
    label = "SomeTool"

    def getParameterInfo(self):
        # define the parameters
        parameters = [
            arcpy.Parameter(...),
            arcpy.Parameter(...),
            arcpy.Parameter(...),
            ]
        # change default values, filters, and visibility
        parameters[0].filter.list = [1, 2, 3]
        parameters[1].enabled = False
        parameters[2].value = "default"
        return parameters

    def updateParameters(self, parameters):
        if parameters[0].value == 1:
            parameters[1].enabled = True
        else:
            parameters[1].enabled = False

    def updateMessages(self, parameters):
        parameters[0].setWarningMessage("You have been warned")

 

 

 

For more, here'S the official doc: https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/parameter.htm 


Have a great day!
Johannes
0 Kudos
CarlBeyerhelm
Frequent Contributor

Perfect!  Thank you.

I'd been trying to use the params[5].enabled = False format from ToolValidator instead of parameters[5].enabled = False.

0 Kudos