Examples of in-line variable substitution with ModelBuilder system variables
ModelBuilder provides two built-in system variables that can be used in iteration workflows. These two system variables contain the current iteration number and the current list index: %i% refers to the current list position in a list variable (the first position is zero), and %n% refers to the current model iteration (the first iteration is zero).
Using the %i% system variable with in-line variable substitution
For models that run a process on a list of inputs, each time the process runs, the output will have the same name as the output from the previous run of the process, and the previous output will be overwritten. To avoid overwriting previous outputs in successive iterations, append the name of the output with %i%, which will give each output a unique name that indicates its position in the list of inputs.
Using the %n% system variable with in-line variable substitution
%n% gives the current model iteration number and is used in an iterating model. In the example below, the For iterator is used to iterate a model four times. The output of the Buffer tool is used as feedback into the tool as input. The model iterates and creates a new output at each iteration. %n% is used in the output name of the Buffer tool to give the output of each iteration a new name.
If you are using %n% in the output name of a model parameter, and the model is run from its tool dialog box in ArcMap or ArcCatalog, the iteration number of the application is substituted for %n%. Since the iteration number %n% of the application is 0, the model tool will fail after one iteration with the error message "ERROR 000622: Failed to execute (Tool). Parameters are not valid." In this case, you must either change the variable so that it is not a model parameter or remove %n% from the output name.