Select to view content in your preferred language

How to provide a checklist of values as a parameter

1907
3
Jump to solution
11-21-2013 06:35 AM
JonathanBailey
Frequent Contributor
I'm creating a new tool (probably will be a Python script tool) in which I want to provide the user with a list of pre-defined values to choose from, similar to the way in which a user can choose scales in the Extract Map Server Cache tool (see attached screen shot). How can I do this?

[ATTACH=CONFIG]29269[/ATTACH]
0 Kudos
1 Solution

Accepted Solutions
JonathanBailey
Frequent Contributor
Hi Wayne,

Thanks for your response. You pointed me in the right direction. In fact, it seems that it's even easier to do this in ArcGIS 10.2. On the Parameters page of the Add Script wizard, you can create the parameter, then choose MultiValue=Yes, and Filter=Value List.

[ATTACH=CONFIG]29365[/ATTACH]

When you choose Filter=Value List, a Value List window opens, in which you can specify a list of values.

[ATTACH=CONFIG]29366[/ATTACH]

Back in the Add Script wizard, you can also specify a set of default values (which will be checked by default when the tool is opened), as a semicolon-delimited list.

The result looks like this:

[ATTACH=CONFIG]29367[/ATTACH]

So, thanks for pointing me in the right direction!

Jon.

View solution in original post

0 Kudos
3 Replies
T__WayneWhitley
Honored Contributor
At the script tool properties, same place you set the parameters, source pathname to the py script, etc., there's also a Validation tab...if you click the 'edit' button, the ToolValidator class code will be opened which you'll need to modify.

For example, I did some minimal modifications implementing an script tool to update connection properties to layers and made the tool interface to allow selection of any of several SDE connections -- the idea or objective was to aid in cutting down processing time if the user already knew what types of connections existed in the current map doc (so no need to go searching for any not checked off in the tool)...I implemented this at 10.0, and here's how it appears - notice how little I needed to modify (you'll need to compare to the originally loaded code) - I needed change the 'list' in the initializeParameters function and for default checked on I also kept 3 connections checked by default by altering the updateParameters function (for those users unsure what to check on or off):
class ToolValidator:
  """Class for validating a tool's parameter values and controlling
  the behavior of the tool's dialog."""
 
  def __init__(self):
    """Setup arcpy and the list of tool parameters."""
    import arcpy
    self.params = arcpy.GetParameterInfo()
 
  def initializeParameters(self):
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""
    self.params[0].filter.list = ['MonroeGISData', 'MonroeRasterData', 'MCPA', 'MonroeAddressing']
    return
 
  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parmater
    has been changed.""" 
    if not self.params[0].altered:
      self.params[0].value = r"'MonroeGISData';'MonroeRasterData';'MCPA'"
    return
 
  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    return



Almost forgot - you will probably need this (the 10.2 webhelp for this class):

Programming a ToolValidator class
Desktop » Geoprocessing » Creating tools » Creating tools with Python » Creating script tools in a custom toolbox
http://resources.arcgis.com/en/help/main/10.2/index.html#//00150000000v000000

Scroll down to the heading 'filter object' - this is what I used, setting on the Parameters tab a multivalue input param defined by a Value List.

Wayne
JonathanBailey
Frequent Contributor
Hi Wayne,

Thanks for your response. You pointed me in the right direction. In fact, it seems that it's even easier to do this in ArcGIS 10.2. On the Parameters page of the Add Script wizard, you can create the parameter, then choose MultiValue=Yes, and Filter=Value List.

[ATTACH=CONFIG]29365[/ATTACH]

When you choose Filter=Value List, a Value List window opens, in which you can specify a list of values.

[ATTACH=CONFIG]29366[/ATTACH]

Back in the Add Script wizard, you can also specify a set of default values (which will be checked by default when the tool is opened), as a semicolon-delimited list.

The result looks like this:

[ATTACH=CONFIG]29367[/ATTACH]

So, thanks for pointing me in the right direction!

Jon.
0 Kudos
T__WayneWhitley
Honored Contributor
Ah, very nice!  Thanks for the additional feedback, something to look forward to when I upgrade to 10.2.
Excellent, thank you.
0 Kudos