Choosing string from dropdown list rather than typing it into Python script tool?
There are a couple of ways to approach this:
- Create a list of filter values in the parameters property.
- Create the list in the validation script.
I prefer the second route since you have more control over what values are valid as well as extracting unique values from fields.
Going the first route:
Set the data type to string (as shown in your picture) and change the filter type from None to Value List. Here you can add in all the values you want to see in a drop down list. Going the second route:
The advanced route requires modifying your script validation. While this may be overkill based on the your needs, I thought it might be useful in giving you an idea of a more efficient approach that may help for future scripts.
You will need to first initialize the variable under the initializeParameters(self) function. The parameter in your script that will need a dropdown list is based on the parameter number assignment. In your example, you want the 7th parameter, so you will assign values to self.params[6] = "List of Values" (Remember that python index's starts 0)
In the example below, I'm creating a county list for the first parameter self.params[0]. I create an interim dictionary that stores all the municipalities for each county so the dictionary key/value structure = county:[municipalities]. Whatever county the user selects will be passed into the muninicipality dictionary. The drop down list for the second parameter self.params[2], is a list of the municipalities in whatever county. You will also need to add in logic check under the updateParameters(self) function to account for when a user changes the value in the first parameter.
import arcpy
global county_mun_dict
class ToolValidator(object):
"""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."""
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 = Get_County_List()
municipality_list = Get_Municipality_List("ATLANTIC")
municipality_list = sorted(municipality_list.keys())
self.params[1].filter.list = municipality_list
#Setup wildcard dropdown list
query_type = ["Equals", "Contains"]
self.params[4].filter.list = query_type
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."""
if self.params[0].altered:
municipality_list = Get_Municipality_List(self.params[0].value)
municipality_list = sorted(municipality_list.keys())
self.params[1].filter.list = municipality_list
return
def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
Resources:
python script tool validation checkboxes to radio boxes?
How to Change Parameter Type from Optional to Required
Alter validation in ArcGIS script tool
How to create a checkbox parameter in a ArcGIS custom Python tool?
Can one parameter choice on Python toolbox tool set Display Names of other parameters?
ArcGIS: What is the behavior of ToolValidator class and checkboxes?
ArcGIS Resources:
Customizing tool behavior in a Python toolbox
Programming a ToolValidator class