Select to view content in your preferred language

How to make one of a script tool parameter showing dynamicly?

1700
5
12-29-2016 05:10 PM
TieshengWu
Regular Contributor

Hi all, I am wondering if it's possible to make a script tool parameter showing or hiding depending on other parameter's value by user's inputing through coding in Validation or some other trick? 

0 Kudos
5 Replies
BlakeTerhune
MVP Regular Contributor

It's part of the validation.

Understanding validation in script tools—Help | ArcGIS for Desktop 

Parameter objects have a Boolean enabled property

Programming a ToolValidator class—Help | ArcGIS for Desktop 

A parameter's value property returns an object, unless the parameter isn't populated, in which case the value returns None. To safeguard against a parameter not being populated, use a if check prior to using its value.

The code snippet below tests whether the value is equal to the string "Get Spatial Weights From File". This test works because the parameter data type is a string.

# If the option to use a weights file is selected, enable the
#   parameter for specifying the file, otherwise disable it

if self.params[3].value:  # check that parameter has a value
  if self.params[3].value == "Get Spatial Weights From File":
    self.params[8].enabled = True
  else:
    self.params[8].enabled = False
TieshengWu
Regular Contributor

Thank you Terhune. It almost solve my problem, but it will be better if  parameters invisible instead unselectable, or is it possible to popup another script parameters panel waiting for user's interactive inputs as an alternative?

0 Kudos
BlakeTerhune
MVP Regular Contributor

I don't think there's that much control over the script tool interface. I don't have a lot of experience with it though, maybe someone else knows for sure.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

I don't know if this will work, but if you choose a parameter type of "Derived" it will not show, but the user also doesn't have an option to choose either.  But maybe you can work with that to get what you need.

Setting script tool parameters—Help | ArcGIS for Desktop 

TieshengWu
Regular Contributor

Thank you Strauch, I read the subject you posted and am working with ModelBuilder to see whether it can do. 

0 Kudos