8

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

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 8, 2014 at 7:00
0

1 Answer 1

9

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
answered Apr 8, 2014 at 11:47
9
  • 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? Commented 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. Commented 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 confusing Commented 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? Commented 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. Commented Apr 8, 2014 at 13:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.