A quick tour of using preconditions
Preconditions can be used to explicitly control the order of operations in a model. For example, a process can be made to run after another process by making the output of the first process a precondition to the second process. Any variable can be made a precondition to tool execution, and any tool can have more than one precondition.
Example 1—Setting a data variable as a precondition
In this example, two separate but related processes will be connected using a precondition so that one process executes before the other. The first string of processes creates a new feature dataset within a new file geodatabase. The second process clips a feature class to a study area, then writes the output to the newly created feature dataset.
If the model above is executed as is, there is no way to control the order of operations; the Clip tool may execute before its output location is even created, resulting in an error. One approach to avoid this is to run the Create File GDB and Create Feature Dataset processes first, by right-clicking the process and selecting Run, then lastly run the Clip process.
However, this method of running individual tools only works within ModelBuilder. What if the model must be run outside ModelBuilder or you need to execute the entire model at once, not tool by tool?
Preconditions can be used to explicitly control the order of operations in a model. In the model below, the new Feature Dataset variable is made a precondition to the Clip tool. By doing this, Clip tool not execute until the new feature dataset is created.
Example 2—Setting a Boolean variable as a precondition
In the example above, a feature dataset variable was used as a precondition to a tool. A Boolean variable used as a precondition behaves differently from data variables like feature datasets or feature classes. With Boolean variables, ModelBuilder reads the TRUE or FALSE value of the variable instead of determining whether the data has been created. If the value is TRUE, the precondition is satisfied and the dependent tool will execute. If the value is FALSE, the precondition has not been satisfied and the dependent tool will not execute. In the example below, a Boolean variable, Run Model, is made a precondition to a tool.
The Boolean precondition variable is made a model parameter so it is exposed when the model tool dialog box is opened. In the tool dialog box, checking the Run Model parameter sets the variable to TRUE, so when the model is executed, the dependent process within the model (Add Field) will execute. If the Run Model parameter is not checked, the Boolean variable is FALSE, and when the model is executed, the dependent process within the model will not execute, as the precondition is not met. If the parameter is not checked, running the model will issue a warning message: "The process did not execute because the precondition is false."
To learn more about creating model variables of different types, see Creating variables.
Example 3—Setting a long integer variable as a precondition
A long variable (a long integer) behaves the same way as a Boolean variable when set as a precondition. If the value of the long variable is a positive integer, it evaluates to true and the dependent process will execute. If the value is 0 or negative, it evaluates to false and the dependent process will not execute.