Select to view content in your preferred language

Adding a drop down menu to a python script

3822
1
11-17-2010 03:08 PM
ElwoodGunther
Deactivated User
I have a python script that I am running in ArcToolbox.  Right now it clips data into a particular feature dataset in a File Geodatabase. Does anyone have a way that when the user chooses a file geodatabase, a drop down menu gets populated with all of the Feature Datasets in that File GDB for the user to choose from?

Thanks
0 Kudos
1 Reply
LoganPugh
Frequent Contributor
You'll need to write validation code in the script tool's ToolValidator class to update the filter of a String parameter which will act as a combo box, the values in the filter corresponding to the feature datasets in the geodatabase.

More info here: http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Customizing_script_tool_behavior

This code seems to work:
class ToolValidator:
  """Class for validating a tool's parameter values and controlling
  the behavior of the tool's dialog."""

  def __init__(self):
    """Setup the Geoprocessor and the list of tool parameters."""
    import arcgisscripting as ARC
    import os
    self.GP = ARC.create(9.3)
    self.params = self.GP.getparameterinfo()

  def initializeParameters(self):
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""
    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 self.params[0].Value:
        self.GP.Workspace = str(self.params[0].Value)
        datasets = self.GP.ListDatasets("","Feature")
        if len(datasets) > 0:
            self.params[1].Filter.List = datasets
            if not self.params[1].Altered or self.params[1].Value not in datasets:
                self.params[1].Value = datasets[0]
        else:
            self.params[1].Filter.List = []
            self.params[1].Value = None
    else:
        self.params[1].Filter.List = []
        self.params[1].Value = None
    return

  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    return
0 Kudos