0

I am trying to connect three models I build in ModelBuilder within an ArcPy script.

The first model gets its parameters defined by the user. Whereas the other two models will get some parameters from the output of the first model. I use inline variable substitutions in all of the models which leads to the main problem.

The output of the first model (.shp) is saved as a python variable that I try to pass as a parameter to the second model. When I print this variable, I get the filename with the inline variable substitutions (%Name%_filename.shp).

print(kom_ug)
# C:/Users/bjbr/Desktop/test_bjoern/test/shape\%Name%_ug.shp

This causes the error. The second model isn´t able to find the variable in the directory since the shapefile is stored as file_filename.shp.

Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module>   File "C:\Users\bjbr\Documents\ArcGIS\Toolbox.tbx", line 26, in KomBufferTool     ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Kommune_Endringer_ug: Dataset C:/Users/bjbr/Desktop/test_bjoern/test/shape\%Name%_ug.shp does not exist or is not supported The value does not exist.

When I hardcode the variable name the error disappears, but I would like to work with these inline variable substitutions to comfortably handle a higher volume of data.

Does someone have an idea how to work with inline variable substitutions when calling a model in ArcPy?

  • What do you mean exactly with variable inline substitutions? You mean something like 'insert something here {}'.format('value to insert')? – Marcelo Villa Mar 21 '18 at 11:56
  • If %Name% is a windows environment variable, you should import os and get the value of %Name%: os.environ['Name'] – Andreas Müller Mar 21 '18 at 12:03
  • Sorry for the misunderstanding. In my models I am using inline model variable substitutions. desktop.arcgis.com/en/arcmap/10.3/analyze/modelbuilder/… – Björn Broschag Mar 21 '18 at 12:06
1

You cannot use inline variable substitution in a file path without using the Parse Path tool. See example 6 below:

http://desktop.arcgis.com/en/arcmap/10.3/analyze/modelbuilder/examples-of-inline-model-variable-substitution.htm

and use the Parse Path tool to separate the full path into its components and then use the dataset name (contained in the Name variable) for inline substitution

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.