How to show different options in Script Tool when selecting different options?

731
5
04-21-2019 07:15 PM
deleted-user-yC5VkbyXzrQR
Occasional Contributor

Hello everyone, 

I'm wondering how I can give different GetParameteres when a certain variable is true. 

For ex. 
If a feature class has more than 1 feature in it I want it to use a different GP tool. I know I can do this in the script easily but I want users to enter in parameters in if the feature class has more than 1 feature in it. 

Tags (2)
5 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Adam,

You will need to apply Script Tool Validation to the tool.  Take a look at the following example:

Customizing script tool behavior—Help | ArcGIS Desktop 

You could specify something like:

def updateParameters(self):
    result = arcpy.GetCount_management(self.params[3].value)
    if int(result[0]) > 1:
        self.params[8].enabled = 1
    else:
        self.params[8].enabled = 0
deleted-user-yC5VkbyXzrQR
Occasional Contributor

Awesome, thanks for the reply Jake. 

So I would need to edit the code in the Validation tab?

see image.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Adam Arcichowski‌ yes that is correct.

0 Kudos
deleted-user-yC5VkbyXzrQR
Occasional Contributor

Jake, 

Now that I think of it, I'm not sure if this will work because the  "arcpy.GetCount_management" will not work on a kmz correct?

If I select a kmz with multiple features in it, can the Validation script run to convert the kmz to a feature layer than use the GetCount function and then have the other parameters come up ? 

0 Kudos
JakeSkinner
Esri Esteemed Contributor

It can, but you may want to be careful with this approach.  From the help:

Called each time the user changes a parameter on the tool dialog box. After returning from updateParameters, geoprocessing calls its internal validation routine.

You will want to make sure the tool is not running the KMZ conversion after each parameter is updated.

0 Kudos