Select to view content in your preferred language

GPValueTable values

4375
3
02-25-2014 10:42 AM
JeffreyOwen1
Occasional Contributor
I am trying to create a python toolbox with a tool that presents the user with a Value Table with 3 columns. I am hoping to insert data into these columns as the user interacts with the tool through "updateParameters", but cannot seem to figure out how to format the values. Can anyone just give me a single line of code that would insert one row of values into the three columns for the value table below?

The only info I could find was here where it just says
"To set default values for a value table parameter, use the values property, and provide the parameter values in a list of list of values."


But every time I try to use a list it errors.

Here is my code that I am using:

        param4 = arcpy.Parameter(
            displayName='Features',
            name='in_features',
            datatype='GPValueTable',
            parameterType='Required',
            direction='Input')

        param4.columns = [['String', 'Features'], ['String', 'Type'], ['String', 'Distance']]
Tags (2)
0 Kudos
3 Replies
FilipKrál
Frequent Contributor
Would it work if you do this right after your code?
param4.values = [['c:/temp/land use.shp','POLYGON','123']]


Or like this if you want multiple default rows filled in:

param4.values = [['c:/temp/land_use.shp','POLYGON','123'],['c:/temp/roads.shp','POLYLINE','456']]


Let us know how you get on, I always wondered how to do this.
Filip.
0 Kudos
JeffreyOwen1
Occasional Contributor
Every time I tried putting something in brackets it gave me an error because it wasn't the right type (str) so I started playing around with it and found that if I put this:

param4.value = "text1;text2;text3"


It would split the text on the semicolon and have that fill out the first column of the table for 3 rows.

Then when I was playing around more I noticed that if I put a space then it would fill out the other columns:

param4.value = "text1 text2 text3"


This would create 1 row with text in each of the 3 columns.

From there I can split it like this:

param4.value = "this" + " " +  "and" + " " +  "that""


So that I can replace the text for a variable to make the values change to what I want them to be.

Doesn't seem very efficient, but if it works I won't complain.
0 Kudos
KennethEggeringAtStantec
New Contributor

I know this post is going on 10 years old, but I came across it and wanted to note a couple things in case other folks land here. @JeffreyOwen1, I do believe param4.columns should be of type "GPString" rather than "String." 

 

Further, to @FilipKrál 's comment, the syntax of the first solution you posted worked for me (i.e., a single list of multiple items, nested in an outer list, as opposed to multiple lists nested in an outer list).  Note that it is indeed "values" with an "s" and not the singular form. 

0 Kudos