Iterate through list of parameterized field values in Model Builder?

639
1
09-30-2011 06:23 AM
JayGregory
New Contributor III
Hello - I know there is a way but can't figure out how to do this in Model Builder.  Currently, my model accepts as a parameter a single feature class.  Later there is a Select statement that uses a hard coded field name in the query section to create a new feature class, and then the rest of the model runs, generating a single output feature class. 
Here is what I would like: once the user chooses the single input feature class, s/he can then create a list of different field names (based on that input feature class).  The field names in this list are used to populate the SQL query in the Select statement (each SQL query accepts only one field name).  The rest of the model runs once for each field name, and spits out the same number of output feature classes as there were input field names.  I hope that makes sense. 
Here is what I can't figure out:  1.  How to create a variable that allows the user to create a list of fields based on the input feature class.  2.  How to iterate through this list of field names, feeding them to the Select statement somehow so the rest of the model runs once per field name.  I can't tell if I need to use an iterator here (and which type of iterator) or a parameter that accepts a list of values, and how to connect it all so it works.  Any assistance would be of great help. 
Thanks!
0 Kudos
1 Reply
ShitijMehta
Esri Regular Contributor
Check if this Blog helps with what you are trying to do. Download the script tool to generate a dynamic value list. You can use the tool as shown in the example.

If at all you want to output the field name as well, modify the script to have an additional derived output and set that derived output to be something like    arcpy.SetParameter (4, InputField)

Then you can use both the field name and the field value in your SQL query as in-line variable substitution as shown in the blog example.
0 Kudos