Use inline variable subsitution to set INPUT data path and name in model builder

3074
5
11-22-2012 08:12 PM
ChristinaLi
New Contributor
Is it possible to use inline variable subsitution to set the INPUT path and name of layers which are needed in the second half of a model?

Please see the attached model. What I want to do is:
1. For each feature class in the workpace, I want to select the features intersecting with the area of interest, then export them to a new feature class.
2. I want to apply existing symbology layers of the original feature class to each of the new feature class respectively. I make sure the symbology layers has the SAME NAME as the original feature class.
3. Package the new feature class and the symbology layer into a layer package, so that I can distribute the data with symbology to other people

I set the path and name of the symbology layer variable to be:   %workspace%\%Name%.lyr   , assuming that all the values of Name variable in earlier part of the model can be picked up here one by one.

But I got ERROR 000732: symbology layer: Dataset %Workspace%\%Name%.lyr does not exist or is not supported

Am I on the right track? Can I use inline variable substitution for INPUT path and names, instead of the usual OUTPUT path and name?

Your help is much appreciated!!!

Christina Li
Spatial Analyst
Gold Coast City Council
Queensland, Australia
0 Kudos
5 Replies
MarcinGasior
Occasional Contributor III
When you use %Workspace% inline variable, it refers to Current Workspace variable from Environmets settings.

What you can do is to set Current Workspace environment setting equal your Workspace inline variable.
Second and more straightforward way is to rename Workspace inline variable to eg. InputWorkspace and use this name layer path:
%InputWorkspace%\%Name%.lyr
0 Kudos
curtvprice
MVP Esteemed Contributor
I set the path and name of the symbology layer variable to be:   %workspace%\%Name%.lyr   , assuming that all the values of Name variable in earlier part of the model can be picked up here one by one. 


One more thing, use preconditions to make sure the tools run in the order needed to make paths valid at runtime.
0 Kudos
ChristinaLi
New Contributor
Hi Marcin and Curtis,

Thanks for your reply. Sorry I have been away from work, so could not respond earlier.

I tried both your suggestions, but still got the same error. Please see the attached JEPG.

I suspect the problem is: %Name% is not recognized as inline variable substitution, but just a series of characters. I tested by keeping %InputWorkspace% in the input window, but use an existing layer file name. The model ran no problem. But once I used %Name%.lyr to replace the existing layer file name, I got the same error.

I think the potential reason is: Inline variable substitution is designed for elements going along the flow of the model, instead of an element (symbology layer variable in this case) appearing half-way in the model and use inline variable substitution for input.

Am I on the right track?

Thanks heaps for your input.

Christina
0 Kudos
ShitijMehta
Esri Regular Contributor
Hi,

Ok I see what you are doing based on your first attachment on this forum.

Explanation:

I think you are trying to run this model from the model tool dialog, Correct?


  • If yes, your layer file connected as input to the Apply Symbology from Layer tool has the value %workspace%\%Name%.lyr...

  • Now, when you run a model from its tool dialog and have %Workspace% in any of your parameter it is going to look at for the current workspace set in the environment settings at the ArcMap level i.e. set from the Geoprocessing tab on ArcMap>environments option . The workspace set here must match the workspace you really want to point to find the layer. This means that you need a map document with a set current workspace to always accompany the model when you share your model.

  • OR if you do not want a map document to be shared and if you decide to you a default workspace in the environments setting set at ArcMap level then this default workspace will not have the layer file you are pointing at.


  • Now the second part %Name%.. this Name really points to a variable in the model. When you run it as a model tool this %Name% will not work.



Testing:

If you running the model from within a model and still see this error check these things to begin:

  • %Workspace% which points to the workspace variable connected to your iterator is the folder that contains your layer file.

  • Check the value of the variable Name (output of the iterator) to which the %Name% is pointing at, and make sure the value of the variable and the name of the layer in the workspace are exactly the same.


If the above two points are OK then try this:

  • Instead of the %Workspace% use the actual path to the workspace and then append %Name%.lyr in the end.

  • If this fails try to use the exact layer file name and path and run the model for just one feature class and its  corresponding layer file.

  • Do you really need the input to Apply Symbology From Layer tool as a model parameter?

[INDENT][/INDENT]


If nothing works write back and share your model and a sample of your data and the layer file.
0 Kudos
ChristinaLi
New Contributor
Hi shitij mehta,

Thank you very much for the detailed explanation and testing steps!

But the model still did not work after I followed every step you laid out. The model did not run from the model tool dialogue, or from within a model. I then followed the two steps below:

â?¢Instead of the %Workspace% use the actual path to the workspace and then append %Name%.lyr in the end.

The %Name% part triggered the error in attachment 1
â?¢If this fails try to use the exact layer file name and path and run the model for just one feature class and its corresponding layer file.

Worked.

So I believe the problem is:
%Name% is not recognized as an inline variable substitution, but just a bunch of strings.


â?¢Do you really need the input to Apply Symbology From Layer tool as a model parameter?

Not really, so I unchecked the model parameter option. But the model still did not run.

I also tried to use â??Calculate Valueâ?� to construct the exact name of the symbology layer by adding the value from Name variable with extension â??.lyrâ?�. I managed to get the output string (exact symbology layer name) no problem. But %SymbologyLayerName% still cannot be recognized by Apply Symbology From Layer. (Please see attachment 2)

So, I have included the models, two feature classes and their corresponding symbology layers in the attached zip file. Please refer to the last attachment "database structure environment setting.JPEG" when you unzip the files to your local drive.

Can you please take a look and let me know if there is a solution, or I have to resort to Python codes (which I am not familiar with). Thank you so much for your help!

Christina
0 Kudos