Inline model variable substitution

5319
12
Jump to solution
03-28-2012 08:33 AM
BillTrask
New Contributor II
Is it possible to use the inline model variable substitution when the input is a list of variables?  I would like to be able to select a number of input soil shapefiles, clip each according to the same clip features, then name each resulting clipped soil shapefile according to its original input name. 

I've made a general input feature (to be clipped) called 'Soil', set it to parameter and a list of values.  I've parsed the name of 'Soil' and set the output variable from here as 'SoilName'.  Finally, I use inline variable substitution for my clipped output feature by calling it 'Clipped_%SoilName%'.  When I run the model, I input 2 features to be clipped: the soils shapefiles of Herkimer County and Montgomery County (in that order).  When it's finished running, I only get the clipped Montgomery County with the name 'Clipped_Herkimer'.

I know that there are other methods of inline variable subing, such as the %i% option, but in this case the name is essential because I will be using this later in the model to perform a table join with each County's massive soils table.  Any thoughts?
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor
Is it possible to use the inline model variable substitution when the input is a list of variables? 

I know that there are other methods of inline variable subing, such as the %i% option, but in this case the name is essential because I will be using this later in the model to perform a table join with each County's massive soils table.  Any thoughts?


If you use the Iterate Multivalue tool (or any other iterator), the iterator generates variables on each loop, just for this purpose. If what you are getting isn't exactly what you need, you can use the Calculate Value tool on each loop to manipulate these values to create the output pathname you want. use the output of the Calculate Value tool in percents embedded in your output file name, for example "Soil_%shapename%.dbf". Be sure and use preconditions to make sure the variable gets calculated by Calculate Value before you run the tool that uses its name for an output.

View solution in original post

0 Kudos
12 Replies
markdenil
Occasional Contributor III
I would suggest converting your model to a python script (export the model and clean up the code). Then you can loop through lists or dictionaries to your heart's content.

I find Model builder works best for fast prototyping; when the process works once through in the model I then export it and build in the looping and error checking and whatnot.
0 Kudos
EdithFergus
New Contributor
I would suggest converting your model to a python script (export the model and clean up the code). Then you can loop through lists or dictionaries to your heart's content.
0 Kudos
BillTrask
New Contributor II
Right, but there should be a way to do it in the model builder.  Otherwise the option of using inline variable substitution is quite limited.  Any other suggestions?
0 Kudos
curtvprice
MVP Esteemed Contributor
Is it possible to use the inline model variable substitution when the input is a list of variables? 

I know that there are other methods of inline variable subing, such as the %i% option, but in this case the name is essential because I will be using this later in the model to perform a table join with each County's massive soils table.  Any thoughts?


If you use the Iterate Multivalue tool (or any other iterator), the iterator generates variables on each loop, just for this purpose. If what you are getting isn't exactly what you need, you can use the Calculate Value tool on each loop to manipulate these values to create the output pathname you want. use the output of the Calculate Value tool in percents embedded in your output file name, for example "Soil_%shapename%.dbf". Be sure and use preconditions to make sure the variable gets calculated by Calculate Value before you run the tool that uses its name for an output.
0 Kudos
BillTrask
New Contributor II
Thanks, that worked.  The only pitfall is that I had to manually enter in the output address: 'G:\Test\%Value%Clip.shp' for each of the output variables, which is both odd and self-defeating.  You would think that the inline substitution would be able to handle this.  If I don't copy and paste this same address onto the next line of the 'batch' table, I merely get the last clipped shapefile with the first shapefile's name.
HenrikSvenningsen
Occasional Contributor
The only pitfall is that I had to manually enter in the output address: 'G:\Test\%Value%Clip.shp' for each of the output variables.....

Have you tried: %Workspace%\%Value%Clip.shp....and just befor that set your workspace to: G:\Test
0 Kudos
BillTrask
New Contributor II
The only pitfall is that I had to manually enter in the output address: 'G:\Test\%Value%Clip.shp' for each of the output variables.....

Have you tried: %Workspace%\%Value%Clip.shp....and just befor that set your workspace to: G:\Test


Yes, I tried that with the same result.
0 Kudos
ShitijMehta
Esri Regular Contributor
Dear wjtrask,

Couple of things to check and try:


  1. Share your model or a snap shot of your model.


  2. How are you running the model?

  3.      By editing a model and running from within ModelBuilder?
         From its tool dialog?

  4. If you are running from tool dialog - Make sure that your outputs are not intermediate (especially the one on which your inline variable substitution depends)  Right click your green ovals and uncheck the intermediate such that they are not deleted after the model runs. Experiment with this. You can always check it intermediate if you do not need them after you run the model and also after you make sure that downstream tools are not dependent on any of the outputs marked as intermediate


Try these at 10.0:
Do not use a list variable INSTEAD

Put all your shapefiles in one place and use the Iterate Feature Class Iterator. This iterator has two outputs 1) the feature class path which you can connect to the Clip tool downstream, 2) Name- which is the name of the feature class. Use this variable name in your output as %Name%.

or

If you are using Multivalue Iterator use the Parse Path tool and set the second parameter of that tool to Name. Use the output of Parse path as inline in your downstream tools. Set precondition from Parse path to the next tool  Clip.
0 Kudos
CrystalCarreon
New Contributor
shitijmehta:
Thanks so much for sharing! I used the parse path tool for inline variable input/output while using the iterate multivalue tool and it worked brilliantly!

Thanks again,
Crystal
0 Kudos