If-then-else logic is a powerful concept for performing different actions based on different conditions. If-then-else logic can be explained as such:
- IF some condition is true
- THEN perform an action
- ELSE the condition is false
- perform a different action
In ModelBuilder, if-then-else logic can be added using the set of built-in Logical tools or with custom Python functions or script tools.
Logical tools are a category of ModelBuilder utilities that help you control the flow of processes in a model and enable if-then-else branching logic.
Evaluates if the specified data exists.
Evaluates if the input data has the specified fields.
Evaluates if the input data has a selection and if a certain number of records are selected.
Evaluates if the input data has the specified coordinate system.
Evaluates if the input data matches the specified data type.
Evaluates if a feature class is of the specified feature type.
Evaluates if the values in an attribute field match a specified value, expression, or second field.
Evaluates if the row count of the input data matches a specified value.
Evaluates if the inputs have a specified spatial relationship.
The Merge Branch tool merges two or more logical branches into a single output.
Stops iteration if all inputs values meet the specified condition of True or False. It is functionally similar to the While iterator but is useful to stop a model if there is one While iterator in a model and no additional iterators can be added.
In addition to the built-in Logical tools in ModelBuilder, you can write your own functions and tools to perform if-then-else branching using custom Python functions with the Calculate Value tool. These functions can test conditions using a variety of arcpy and other Python capabilities, and output Boolean true and false variables. Similarly, you can write a Python script that tests conditions and outputs Boolean true and false variables, make the script into a geoprocessing script tool, and add the script tool to your model.