How to use attributes from specified field as input parameter list

540
5
03-11-2024 12:01 AM
Labels (3)
LindsayRaabe_FPCWA
Occasional Contributor III

I swear I've seen this done before, but can't for the life of me figure out how to do it or find it again. I want to set a model builder input parameter to return all the values in a specified field of a set layer as the choice list. This way, as the layer grows and more values are added, it will give you the option to select a value and run a tool using that value as a filter for other layers that are related to it. This also removes the need to manually type in a value, reducing human error. 

I've seen the critique of this elsewhere advising against it because of the potential for huge lists, but in this situation, it won't be an issue. Obviously I want distinct values - not repeats of values if they occur more than once. I thought I'd seen it done with a Collect Values loop of sorts with the input variables of a selection tool. 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
5 Replies
DanPatterson
MVP Esteemed Contributor
0 Kudos
LindsayRaabe_FPCWA
Occasional Contributor III

Nope - it was definitely an Esri community post explaining how to do it. Just can't find it for the life of me! It used all standard Model Builder functions. Something like Add a GP tool, add a layer or feature class, use Collect Values to get the field values and set that as a model parameter and also used as an in-line variable or input to the tool? I'll keep digging!

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
LindsayRaabe_FPCWA
Occasional Contributor III

Found this blog post which seems to be getting closer (though very old). Generating a choice list from a field (esri.com)

Will give it a whirl and see if I can make it work! Swear it didn't need all this extra stuff though. 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
LindsayRaabe_FPCWA
Occasional Contributor III

Right! Not how I remember this working, but it works and is simple enough! 

Refering to this 2011 blog post, i downloaded a template python script tool from here which is summed up in the screenshot below. 

LindsayRaabe_FPCWA_10-1710228198828.png

The script tool uses arcpy to set the input features, field and field value. In my use case, I only have the Field value set to be selectable from a drop down list (parameter) but you could set all 3 and the field and value would be dependant on the feature class selected. The output Value is then used in subsequent GP tools for selecting data (in my case, select by Attribute and Append). 

Quite a simple solution in the end! If I find the other solution that I believe also achieved this, I'll share that here too. 

 

***EDIT***

I removed this as the solution because it seems to be a bit glitchy. The first time it ran, it did generate the list, but then that list never seemed to update for subsequent runs as new values were added to the feature class. Shall keep digging!

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
LindsayRaabe_FPCWA
Occasional Contributor III

Found the post I was thinking of. Turns out it was to parse a list of Field names to the selection list - not a list of attributes from a field. 

Use Field List from Input Feature Class as Parameter in ArcGIS ModelBuilder - Geographic Information...

Have found this one as well, but haven't had success yet in butchering it to make it work. 

arcgis 10.0 - Extracting by Attribute Using ModelBuilder with User Input? - Geographic Information S...

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos