ArcGIS Python – How to Select All Values by Default in Multivalue Parameter

arcgis-10.2arcpypython-toolboxtool-validation

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

Best 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

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
Related Question