I am trying to be able to add a list of years (or return periods) to a python toolbox tool I want to create. In the getParametersInfo function, I am currently setting up a parameter as a "GPString"
datatype and want it to be a multiValue list. Here is my current code:
import arcpy
class Toolbox(object):
def __init__(self):
self.label = "Toolbox"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [TestParameters]
class TestParameters(object):
def __init__(self):
self.label = "TestParameters"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
param0 = arcpy.Parameter(
displayName ='Do Nothing Here:',
name ='in_features',
datatype ="GPFeatureLayer",
parameterType ='Required',
direction ='Input')
param1 = arcpy.Parameter(
displayName ='Enter Return Periods as Years',
name ='tbl_features',
datatype = "GPString", #"GPValueTable", #"GPTableView", #"DETable", #
parameterType ='Required',
direction ='Input',
multiValue=True)
param1.filter.type = "ValueList"
param1.filter.list = []
params = [param0,param1]
return params
def isLicensed(self):
return True
def updateParameters(self, params):
param1.filter.list = []
return
def updateMessages(self, params):
return
def execute(self, params, messages):
arcpy.AddMessage("Testing Tool, nothing here yet")
arcpy.AddMessage(params[1].valueAsText)
return
However, when I pull up the tool in ArcCatalog and open the tool prompt I get an empty box. I expected that, but the "Add Value" button does not allow me to add any values. I would like to add years values such as "2"
, "5"
, "10"
, "100"
, "500"
, & etc...
Am I missing something that should go inside the updateParameters function? Or is there a way to enable the "Add Value" button? It would be nice not to have to hard code year values, as others may be using this script later and may have different years they need to input. This is why I left the param1.filter.list = []
as a blank list, as the ESRI documentation for it doesn't cover how to enter values after the tool is opened.
Or is there a different type of parameter that can easily do this? I've tried the values commented out on the datatype line for param1
. If any of those would work, which one might help me be able to customize this?