+ Reply to Thread
Results 1 to 2 of 2

Thread: Generating lists for parameters in a script tool

  1. #1
    Tyler Quick
    Join Date
    Oct 2011
    Posts
    2
    Points
    0
    Answers Provided
    0


    0

    Default Generating lists for parameters in a script tool

    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.

  2. #2
    Luke Pinner
    Join Date
    May 2010
    Posts
    316
    Points
    280
    Answers Provided
    31


    0

    Default Re: Generating lists for parameters in a script tool

    You can use a ToolValidator class. This is set in the script tool properties dialog in the Validation tab.

    Something like:
    Code:
    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

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts