Now you know series - 2 - Using Inline Variable Substitution

630
3
08-28-2023 05:23 PM
ShitijMehta
Esri Regular Contributor
5 3 630


In ModelBuilder
, you can substitute the value or dataset path of a variable by enclosing the variable name between percent signs (%Variable Name%). Substituting variables in this manner is called inline variable substitution. There are three categories of such variables

  1. Any variable existing in a model
  2. System variables that are added in the product such as %scratchGDB%, %scratchFolder%, %t% for time or %n% for iteration number
  3. Workspace Environments such as %scratchworkspace% or %workspace%

Examples of where inline variable substitution can be used includes:

  1. In an SQL query when the variable is exposed as a model parameter and the value is unknown until provided by the user.
  2. In any tool where there is no direct data type compatibility between an existing variable and a tool parameter. For example,
    1. In Calculate Field tool, when the value of the expression comes from a string variable which cannot be directly connected to the expression parameter.
    2. In Calculate Value tool where a variable data type can be casted to a different data type before passing it to another tool.
  3. In output path using system variables such as %scratchGDB% and %scratchFolder% that point to the project workspace.
  4. In output path using ModelBuilder workspace variables %scratchworkspace% and %workspace%, that point to the environment set in the model.
  5. In the output name if it needs a current time stamp %t% or an iteration number %n%.

To understand more, check out this video created by our summer intern, Atreyi Guin. 

Additional resources:
Inline variable substitution help

3 Comments