Examples of inline model variable substitution

Any variable in the model can be used as a variable substitute by enclosing the variable name in percent symbols (%variable name%).

Example 1

In the model below, a workspace variable, Data Workspace, has a value of C:\Data.gdb. This workspace location is substituted as an inline variable in the Project tool parameters by enclosing the variable name in percent symbols. At run time the actual variable value, C:\Data.gdb, is substituted for %Data Workspace%.

inline data workspace

Example 2

When the iterator Iterate Feature Classes runs, it creates an output variable for both the path of the feature class and the name of the feature class. The value in the Name variable can be used to construct the path to the Projected Feature Class. When the tool executes, %Name% is replaced with the name of the feature class.

Iterator output as inline

Example 3

Parcel ID is a model parameter that is specified when the model tool is run. This variable is used in the Expression parameter of the Select Layer By Attribute tool as "Parcel" = '%Parcel ID%'. When the tool runs, %Parcel ID% is replaced with the parcel ID (9 in the case below) , and only those parcels with an ID of 9 are selected.

Use of inline in Select Layer By Attribute tool

Example 4

This model contains two variables: Number of Residents and Waste Per Person Per Year. These variables are used in the Calculate Value tool expression by enclosing them in percent symbols. When the Calculate Value tool runs, the variable names will be substituted with their specified values and multiplied together to calculate Total Waste Per Year.

Use of inline in Calculate Value tool

Example 5

Miles to Meter is a variable in the model that contains a conversion factor for the number of meters in one mile (1,609.344). The input has a distance field with mile values. The Calculate Field tool uses the values from the distance field (in miles) to multiply with the conversion factor and generate the distance in meters. The expression of the Calculate Value tool is Miles * %Miles to Meter%. When the tool is run, %Miles to Meter% is replaced with 1609.344.

Use of inline variable in Calculate Field tool

Example 6

The example below shows the incorrect way to use inline variable substitution in a model and how the problem can be corrected.

The Input variable contains the valueC:\ToolData\Road.shp. When used as an inline substitute in the output name as C:\Scratch\%Input%, the tool will give an error. This error occurs because the Input variable contains the path, name, and extension of the dataset, causing the substituted value to be C:\Scratch\C:\ToolData\Road.shp—an invalid path. To correctly handle this situation, use the Parse Path tool to separate the full path into its components, then use dataset name (contained in the Name variable) for inline substitution.

How not to use inline

Related Topics


9/13/2011