HOW TO
Iterate operations in Model Builder in ArcGIS Pro allow users to perform repetitive tasks on multiple datasets or features. However, there is a limitation when it comes to using the values obtained from iterate operations in expressions, such as in the "Select Layer by Attributes" or "Make Feature Layer" tools. This article presents a solution to overcome this limitation by creating a script tool that accepts two strings: the field name and the field values. The script tool then returns an expression string that can be used in various tools within Model Builder.
import arcpy # Get the input parameters field_name = arcpy.GetParameterAsText(0) field_value = arcpy.GetParameterAsText(1) # Create the expression expression = f"{field_name} = '{field_value}'" # Set the output parameter arcpy.SetParameterAsText(2, expression)
Below is the UI of the script tool:
By following these steps, you can effectively use the values obtained from iterate operations in expressions within Model Builder in ArcGIS Pro. This solution provides a flexible and efficient way to automate repetitive tasks and perform complex spatial and non-spatial analyses.
As a use case, let us assume we need to export KML from a layer based on the unique values of a field. Hence we Iterated Field Values and connected the output to the script tool as a field value and defined the field name in the script tool manually as a one time declaration. Assign a precondition to the script tool to ensure it runs only after the iterate operation has completed successfully. We are now able to use the output of the script tool as an expression on the Select Layer By Attributes tool and further use Layer to KML with the Iterator inline variable in the output name to generate unique KML files by the field value.
Get help from ArcGIS experts
Download the Esri Support App