Setting multivalue parameters to True

2459
4
Jump to solution
03-14-2013 04:18 PM
JonPedder
Occasional Contributor II
Hi all, is there a way to set the default values in a multivalue Parameter to True or Selected?

Thanks
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
T__WayneWhitley
Frequent Contributor
I did just this for a tool last week - I'm at 10.0 and used the ToolValidator, simple changing (or adding) 3 lines:
class ToolValidator:   """Class for validating a tool's parameter values and controlling   the behavior of the tool's dialog."""     def __init__(self):     """Setup arcpy and the list of tool parameters."""     import arcpy     self.params = arcpy.GetParameterInfo()     def initializeParameters(self):     """Refine the properties of a tool's parameters.  This method is     called when the tool is opened."""     self.params[0].filter.list = ['val1', 'val2', 'val3', 'val4']     return     def updateParameters(self):     """Modify the values and properties of parameters before internal     validation is performed.  This method is called whenever a parmater     has been changed."""      if not self.params[0].altered:       self.params[0].value = r"'val1';'val2';'val3'"     return     def updateMessages(self):     """Modify the messages created by internal validation for each tool     parameter.  This method is called after internal validation."""     return


The line "self.params[0].filter.list = ['val1', 'val2', 'val3', 'val4']" sets my value list (in this case, for the 1st input parameter ([0]), a multivalue param.

The 2-line block sets up the default 3 vals checked on by default - if what is checkmarked by default is 'altered', then that defines the new input:
if not self.params[0].altered:       self.params[0].value = r"'val1';'val2';'val3'"


As a result, on execution vals 1-3 are on and are fetched correctly at GetParameterAsText and if val4 is checked on, then GetParameterAsText fetches the additional val4.  (or if any other combination is chosen, the input is adjusted accordingly)  Perfect!

Enjoy,
Wayne

View solution in original post

4 Replies
MelanieMaguire
New Contributor III
Is your multi-value parameter for a script tool or an add-in component?  Can you show the outline for the code where you would like to implement this?
0 Kudos
JonPedder
Occasional Contributor II
It's for a script tool. I'm using a string parameter with a value list. Right now the value list is generated in teh script tool but could be created using validation class I guess?

I have 6 string values that I'd like to set by default to True or Checked. So when the script tool is opened the multivalue string check boxes are selected.

I'm not stuck on string as a type, I could easily select another data type and work with that. Using individual Boolean parameters makes the script tool extend too far (too much screen space), unless there's a way to arrange Boolean within the script tool?

Thanks

Jon
0 Kudos
T__WayneWhitley
Frequent Contributor
I did just this for a tool last week - I'm at 10.0 and used the ToolValidator, simple changing (or adding) 3 lines:
class ToolValidator:   """Class for validating a tool's parameter values and controlling   the behavior of the tool's dialog."""     def __init__(self):     """Setup arcpy and the list of tool parameters."""     import arcpy     self.params = arcpy.GetParameterInfo()     def initializeParameters(self):     """Refine the properties of a tool's parameters.  This method is     called when the tool is opened."""     self.params[0].filter.list = ['val1', 'val2', 'val3', 'val4']     return     def updateParameters(self):     """Modify the values and properties of parameters before internal     validation is performed.  This method is called whenever a parmater     has been changed."""      if not self.params[0].altered:       self.params[0].value = r"'val1';'val2';'val3'"     return     def updateMessages(self):     """Modify the messages created by internal validation for each tool     parameter.  This method is called after internal validation."""     return


The line "self.params[0].filter.list = ['val1', 'val2', 'val3', 'val4']" sets my value list (in this case, for the 1st input parameter ([0]), a multivalue param.

The 2-line block sets up the default 3 vals checked on by default - if what is checkmarked by default is 'altered', then that defines the new input:
if not self.params[0].altered:       self.params[0].value = r"'val1';'val2';'val3'"


As a result, on execution vals 1-3 are on and are fetched correctly at GetParameterAsText and if val4 is checked on, then GetParameterAsText fetches the additional val4.  (or if any other combination is chosen, the input is adjusted accordingly)  Perfect!

Enjoy,
Wayne
JonPedder
Occasional Contributor II
Perfect, thanks very much Wayne!
0 Kudos