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.
Unselected values
How can I check all values of multivalue parameter through ToolValidation class using python 2.7?
All selected
1 Answer 1
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
enter image description here
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
-
The problem here is that you don't know what strings will come forehand, so you cannot set them checked on parameter update, isn't it?Alex Tereshenkov– Alex Tereshenkov2014年04月08日 12:13:36 +00:00Commented Apr 8, 2014 at 12:13
-
@AlexTereshenkov In some cases you may not, but in Surya's example, the values are being explicitly added in
updateParameters
, so of course they are known.Evil Genius– Evil Genius2014年04月08日 12:19:34 +00:00Commented Apr 8, 2014 at 12:19 -
1@AlexTereshenkov Sure. I was trying to explain how it worked rather than "paste this into your code," but I can see how it's confusingEvil Genius– Evil Genius2014年04月08日 12:54:33 +00:00Commented Apr 8, 2014 at 12:54
-
1@EvilGenius great answer but I'm curious, where in the Help does it say that sending a list to the value property checks on/off checkboxes?Hornbydd– Hornbydd2014年04月08日 13:19:44 +00:00Commented Apr 8, 2014 at 13:19
-
3@Hornbydd I couldn't find anything in the docs that relates to this, but given that the value is set to a ValueTable containing the selected items when the tool is run, it made sense to set it to a list to select the values beforehand. I tested it and it works, although possibly not documented.Evil Genius– Evil Genius2014年04月08日 13:23:48 +00:00Commented Apr 8, 2014 at 13:23
Explore related questions
See similar questions with these tags.