Python Toolboxes: Using a multiValue Parameter

5986
3
Jump to solution
09-24-2012 07:53 AM
ChanningDale
New Contributor III
In a tool in my Python toolbox, I want to set one of my parameters to multiValue to let the user enter multiple input feature classes or layers. When I go to access the parameter value, I'm not sure what data type/object it's coming in as. I've seen conflicting information in the documentation, that it could be either a delimited string using a semi-colon, or it could be a list. Which one is it or is it something completely different? I've tried working with the parameter in both cases, and I get the same error. The error appears when I try to pass in one of the paths given to me through the parameter:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset '[path to feature class]' does not exist or is not supported
Failed to execute (MakeFeatureLayer).


This tool does work if I don't have the parameter set to multiValue.

Documentation I looked at (both in the custom toolbox and Python toolbox sections):
Defining Parameters in a Python toolbox
Setting Script Tool Parameters

Thoughts? Help?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Occasional Contributor III
.value will be a semicolon delimited string. If you use the .values attribute (note the plural), it will be a list instead, which is likely what you want. We couldn't make .value return a list for backwards compatibility reasons.

View solution in original post

0 Kudos
3 Replies
JasonScheirer
Occasional Contributor III
.value will be a semicolon delimited string. If you use the .values attribute (note the plural), it will be a list instead, which is likely what you want. We couldn't make .value return a list for backwards compatibility reasons.
0 Kudos
ChanningDale
New Contributor III
"parameters[0].values" worked without a hitch.  All I had to do was set that equal to a variable name and then get the value in the list at the right index.  Thank you so much!

fc_list = parameters[0].values
edit_fc = fc_list[0]
0 Kudos
WillAllender
New Contributor III
As a follow-on to this topic, I have a multivalue list and I want to test it for the number of selections made by the user.  If the user selects just one value, I want to enable some other Boolean controls.  If the user selects more than one, I want to disable those controls.

I cannot get the Boolean controls to update as soon as I make a list selection.  I must click somewhere else on the form to get the controls to change status.

code where "feature_class" is my multivalue parameter and the other variables are my Boolean checkboxes.
----------------------------------------------
def updateParameters(self, parameters):
[INDENT]# Get inputs[/INDENT]
[INDENT]update_biweekly = parameters[0][/INDENT]
[INDENT]update_monthly = parameters[1][/INDENT]
[INDENT]update_adhoc = parameters[2][/INDENT]
[INDENT]feature_class = parameters[3][/INDENT]
[INDENT]update_gisp = parameters[4][/INDENT]
[INDENT]update_gis = parameters[5][/INDENT]
[INDENT]update_gisw = parameters[6][/INDENT]
[INDENT]update_countystore = parameters[7][/INDENT]
[INDENT]update_cache = parameters[8][/INDENT]

[INDENT]if update_adhoc.value:[/INDENT]
[INDENT][INDENT]feature_class.enabled=True[/INDENT][/INDENT]
[INDENT]else:[/INDENT]
[INDENT][INDENT]feature_class.enabled=False[/INDENT][/INDENT]

[INDENT]if feature_class.values:[/INDENT]
[INDENT][INDENT]if len(feature_class.values) == 1:[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]update_gisp.enabled=True[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]update_gis.enabled=True[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]update_gisw.enabled=True[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]update_countystore.enabled=True[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]update_cache.enabled=True[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT]else:[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]update_gisp.enabled=False[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]update_gis.enabled=False[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]update_gisw.enabled=False[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]update_countystore.enabled=False[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]update_cache.enabled=False[/INDENT][/INDENT][/INDENT]
[INDENT]return[/INDENT]
----------------------------------------------

Any thoughts on how to get my enabled status to change immediately upon clicking a value in the multivalue list?

Thanks,
Will
0 Kudos