I am using ArcGIS 10.2 and have three parameters, Feature class, field and a multivalue parameter respectively in ArcGIS tool. I populate multivalue parameter with unique values of feature class on selection of feature class and field. Here is the code snippet:
def updateParameters(self):
if self.params[0].value and self.params[1].value:
fc = str(self.params[0].value)
col = str(self.params[1].value)
self.params[2].filter.list = sorted(
set(
row[0] for row in arcpy.da.SearchCursor(fc, [col]) if row[0]
)
)
By default, none of the value is checked in the tool.
How can I check all values of multivalue parameter through ToolValidation class using python 2.7?
Answer
You can set the value of the parameter to the values you want to be checked, at least when using a Python Toolbox. The same should be true for your case.
For example:
def getParameterInfo(self):
p = arcpy.Parameter()
p.datatype = 'String'
p.multiValue = True
p.name = 'test'
p.displayName = 'Test'
p.parameterType = 'Required'
p.direction = 'Input'
p.filter.list = ['One','Two','Three','Four']
return [p]
def updateParameters(self, parameters):
parameters[0].value = ['Two','Four']
return
edit
For your code example this would look like:
def updateParameters(self):
if self.params[0].value and self.params[1].value:
fc = str(self.params[0].value)
col = str(self.params[1].value)
vals = sorted(set(row[0] for row in arcpy.da.SearchCursor(fc,[col]) if row))
self.params[2].filter.list = vals
self.params[2].value = vals
No comments:
Post a Comment