1 Reply Latest reply on Nov 10, 2011 1:02 PM by lpinner

    Generating lists for parameters in a script tool

    azquick
      I am trying to create a custom tool in AcrMap 10 that baically allows me to do a select by attribute within the tool. I have a database of river features and want to select features using the river name listed in a column in the attribute table. I can get the tool to the point where, when run, it will prompt me for river name and I can manually type it in and that works, but is there a way to populate a list of options for the parameter so I don't have to know the exact form of the river name to use the tool? Any help would be appreciated.
        • Re: Generating lists for parameters in a script tool
          lpinner
          You can use a ToolValidator class. This is set in the script tool properties dialog in the Validation tab.

          Something like:
          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."""
          
                  names=set() #Sets only handle unique values
                  rows = arcpy.SearchCursor('Rivers','','','NAME')
                  for row in rows:
                      names.add(row.getValue('NAME'))
          
                  for param in self.params:
                      if param.name == 'RiverName':
                          param.filter.list=list(names)
                          break
          
                  return
          
              def updateParameters(self):
                  """Modify the values and properties of parameters before internal
                  validation is performed.  This method is called whenever a parameter
                  has been changed."""
                  return
          
              def updateMessages(self):
                  """Modify the messages created by internal validation for each tool
                  parameter.  This method is called after internal validation."""
                  return