Variables are elements in a model that hold a value or a reference to data stored on disk. A variable can be created and used as a tool parameter. There are two types of variables:
- Data: Data variables are model elements that contain descriptive information about data stored on disk. Properties of data that are described in a data variable include field information, spatial reference, and path.
- Values: Value variables are values such as strings, numbers, Booleans (true/false values), spatial references, linear units, or extents. Value variables contain anything but references to data stored on disk.
There are many reasons to create and use variables in a model:
- A model variable must be used when defining model parameters.
- Model variables can be easily used to connect multiple tools to the same data or value, without having to specify that data or value on multiple tool dialog boxes.
- Exposing tool parameters as variables can make a model easier to read and understand.
- Model variables allow inline variable substitution to be used in a model.
Creating input data and value variables
There are four ways to create a variable:
- Use the Add Data button on the ModelBuilder toolbar to create a data variable.
- Drag data onto the model canvas to create a data variable.
- Expose a tool parameter as a model variable to create either a data or value variable.
Learn more about exposing tool parameters as variables in a model
- Use the Create Variable option to create a data or value variable.
- Click Insert > Create Variable, or right-click anywhere in a model and choose Create Variable. This opens a Create Variable window with a list of all data types that can be used in a model. This window also provides the option to create either a single value or multivalue variable.
- To create a single variable, scroll to and choose any variable and click OK. This creates an empty variable in the model. You can then add data to the empty variable by double-clicking and opening the variable to navigate to the data on disk.
To create a multivalue variable, choose the variable data type, check the multivalue option, then click OK. On the model tool dialog box, this variable can accept multiple inputs.
Creating output data and value variables
When a tool is added to a model, it automatically creates an output data variable, and the variable is connected to the tool. The output variable remains empty (no color) until all required tool parameters are specified. Once all required tool parameters are specified, the output variable changes color to a default green color.
Changing variable data type
Every variable has an associated data type. To view the current data type or change the data type, right-click a variable, click Properties, then switch to the Data Type tab. The list of data types in the drop-down list are those that are supported by the variable.
- Choose the data variable.
- Right-click and click Properties.
- On the Data Type tab, scroll to and choose the new data type in the drop-down list.
- Click OK to make the change.
The data type of the existing variable is changed.