ModelBuilder - Creating a Variable Picklist

11162
11
Jump to solution
01-19-2012 06:33 AM
MichaelQuinene
New Contributor
Hello,

I am trying to create a picklist containing a number of text variables from which a user can select from options A, B, or C.  Whichever the user chooses, it will be passed as a variable to an SQL query.  For the life of me I cannot figure out how to create such a list, if it s possible through ModelBuilder at all.  Any help would be appreciated.

Thanks,

Mike
0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor
You can create a value list filter for model parameters, among other filter types. Once the user selects a value, it can be accessed by inline variable substitution.

View solution in original post

0 Kudos
11 Replies
DarrenWiens2
MVP Honored Contributor
You can create a value list filter for model parameters, among other filter types. Once the user selects a value, it can be accessed by inline variable substitution.
0 Kudos
MichaelQuinene
New Contributor
You can create a value list filter for model parameters, among other filter types. Once the user selects a value, it can be accessed by inline variable substitution.


Thank you very much, that was exactly what I was looking for!

Mike
0 Kudos
JefferyNighbert
New Contributor
Hi,
I want to create a picklist from a field in a table using model builder.  Is that possible?  if it is how is it done?
Jeff
0 Kudos
JonathanQuinn
Esri Frequent Contributor
Take a look at these two resources; this one is a blog that describes a model that populates a parameter with values in a field, and this one is the link to the model from the resource center geoprocessing gallery.
0 Kudos
PeterKohler2
New Contributor III
Hi

Are you supposed to be able to 'plug' your own data in the script linked to by the ESRI staff above?

I downloaded the model and followed instructions on blog here step by step as suggested. But the model doesn't seem able to accept my data - it only seems to work with provided data.

Trying to execute the model after doing as instructed results in either in an empty output, see "Results Window", or I'm simply unable to select a Type and Field, for example see "Error".  Both images attached as below.

[ATTACH=CONFIG]16776[/ATTACH]

[ATTACH=CONFIG]16774[/ATTACH]

In my data I've tried the following with no success;

  • reduced the number of columns and records as I was getting an "Out of Range" error - this stopped occuring after reducing records from 1000 to 33;


  • created a string column exactly like that used in the example data for the drop list to run off;


  • Tested the sub-model in a new empty model, and also opened up the model and tested it.


Can anyone help with what I've missed (perhaps updating file locations or the like??), or was this tool not designed to take anyone elses data?

Best Regards

Peter
0 Kudos
RichardFairhurst
MVP Honored Contributor
Hi

Are you supposed to be able to 'plug' your own data in the script linked to by the ESRI staff above?

I downloaded the model and followed instructions on blog here step by step as suggested. But the model doesn't seem able to accept my data - it only seems to work with provided data.

Trying to execute the model after doing as instructed results in either in an empty output, see "Results Window", or I'm simply unable to select a Type and Field, for example see "Error".  Both images attached as below.

[ATTACH=CONFIG]16776[/ATTACH]

[ATTACH=CONFIG]16774[/ATTACH]

In my data I've tried the following with no success;

  • reduced the number of columns and records as I was getting an "Out of Range" error - this stopped occuring after reducing records from 1000 to 33;


  • created a string column exactly like that used in the example data for the drop list to run off;


  • Tested the sub-model in a new empty model, and also opened up the model and tested it.


Can anyone help with what I've missed (perhaps updating file locations or the like??), or was this tool not designed to take anyone elses data?

Best Regards

Peter


I have used it with my data and as long as I do not exceed the maximum number of records allowed in the list and account for the field's type I do not get an error with my data.  The model has a Selection query string that is built assuming that your field is a string type, so if your field type is a numeric or date field that will generate an error until you correct the way the inputs build the Select query filter string.

At least several hundred values can be added to the list before an error is generated.  I plan to add code to determine exactly how many values can be added before that error occurs, so that I can halt the list growth and provide a warning to the user.  A seed value parameter could be added to the tool to provide a Like statement or Min and Max limit to prefilter the record set so that the user would have some control of what values will be included in the list while avoiding the index out of range error.  Validation code could be added to let the filter value be optional if no index out of range error is detected and required if the error is detected, rather than just letting the tool fail.
0 Kudos
PeterKohler2
New Contributor III
I have used it with my data and as long as I do not exceed the maximum number of records allowed in the list and account for the field's type I do not get an error with my data.  The model has a Selection query string that is built assuming that your field is a string type, so if your field type is a numeric or date field that will generate an error until you correct the way the inputs build the Select query filter string.

At least several hundred values can be added to the list before an error is generated.  I plan to add code to determine exactly how many values can be added before that error occurs, so that I can halt the list growth and provide a warning to the user.  A seed value parameter could be added to the tool to provide a Like statement or Min and Max limit to prefilter the record set so that the user would have some control of what values will be included in the list while avoiding the index out of range error.  Validation code could be added to let the filter value be optional if no index out of range error is detected and required if the error is detected, rather than just letting the tool fail.


RFairhur24, Thanks for your response. 

I've made sure that my list field is setup exactly like that in the 'Bird' feature clas i.e. String, with 20 characters and while a title shorter then that in the feature class too. I did at the first instance.

RE the 'list limiter' It sounds like a useful addition to the tool, however I'm sure it would solve my specific problem.  I only have two values in my data field, "Graffiti" and "Fly-posting".  So there should only be two items populated in the list if i understand the tool correctly. There were about 3,000 records when "Graffiti" and "fly-posting" are combined, with this many I was getting an "out of range" error.  I thought this meant there were too many records so I reduced them down to 33 in an extract.  The "out of range" error stopped occuring, but it was replaced with the error I posted above...

I plan to use this script to help users pre-select what value in a dataset (i.e. graffiti or Fly-posting) they want to run a Hotspot Analysis on .

Is there anything else I can try?

Many thanks, and Best Regards

Peter

Best Regards

Peter
0 Kudos
RichardFairhurst
MVP Honored Contributor
Is there anything else I can try?


Did you catch the fact in the download that the second parameter for the Field does not have the Obtained From setting correct in the Script tool?  Open the script Properties, go to the Parameters tab, click the Field parameter in the top list (the second parameter listed).  In the settings at the bottom of the dialog make sure the Obtained From setting is pointing to "Feature_Class_Table" (the correct name of the first parameter) and not "Input_Feature_Class_Table".  That was causing me problems until I fixed it.

If that does not help, open the tool in the model and choose the input values again to make sure each parameter responds to the validation script and then screenshot the script input dialog with the input values you are providing (don't cover it up with an error message).  Then screenshot the tableview of the input data.

I just retried my tool and it allowed me to fill in a list with over 35,000 values, so apparently the index value out of range is perhaps due to something in the append to list behavior.  Perhaps upper/lower case, Null values or whitespace values are being excluded from the list and the unique value counter of the cursor and the list index values do not stay in synch.
0 Kudos
PeterKohler2
New Contributor III
Did you catch the fact in the download that the second parameter for the Field does not have the Obtained From setting correct in the Script tool?  Open the script Properties, go to the Parameters tab, click the Field parameter in the top list (the second parameter listed).  In the settings at the bottom of the dialog make sure the Obtained From setting is pointing to "Feature_Class_Table" (the correct name of the first parameter) and not "Input_Feature_Class_Table".


Hi Richard, thanks for your quick and helpful suggestion. 

Did the edit to the Script version, as suggested above, and it seems to work fine now.  However, the model version of the script still appears not to work - producing the same error as before - and it's the output feature class that is the vital part to plug into the rest of my model.  I assume I'd need to apply the same correction as quoted above to the model too, but cant see how that might be done.

If that does not help, open the tool in the model and choose the input values again to make sure each parameter responds to the validation script and then screenshot the script input dialog with the input values you are providing (don't cover it up with an error message).  Then screenshot the tableview of the input data.


I hope I've got what you requested in this quote correct:
[ATTACH=CONFIG]16920[/ATTACH]

For the above screenshot, I right clicked -> edited the model, then opened the script within and set my Featurec lass as the "Feature class/Table".  However, this fails to update the "Field" and "Value", with "Field" drop down not having any options but "Field" and the "Value" still retaining the selection of birds.  As soon as I change the input to my own data the rest of tool no longer validates.  The critical error here says "...Too few parameters expected. Expected 1"

Below is a screenshot of the dialogue box, when I open the tool straight from catalogue.
[ATTACH=CONFIG]16921[/ATTACH]

Again similarly, the Field and Value fail to update with contents of my own feature class.  Same critical error.

Table view screenshot, Field value is highlighted.
[ATTACH=CONFIG]16922[/ATTACH]

Many Thanks

Peter
0 Kudos