Can model builder automaticly update output names?

5919
5
Jump to solution
08-08-2013 09:04 AM
TomKearns
Occasional Contributor II
I have a model built that will take a line.shp file, manipulate it and produce two other .shp files.  The input file as well as the two output files are marked as Parameters.

I would like my output files to be named based on the intitial input file.  As it is now, when the tool is run the parameter inputs default to the name of the file I used to build the model. When a new file is put into the first parameter box, I would like the other two to also update to reflect the change. Is there a way to have the second two parameters update when the first is set?

Thanks.
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor
I was hoping there was an easier answer (like a button to check).


You can use the Parse Path tool to extract the name of an input, then use that model variable in the output file name as something like "out_%base name%.shp".

View solution in original post

0 Kudos
5 Replies
TimWitt
Frequent Contributor
Maybe export your model to python and then insert a script that uses your input names and creates the output naming?
0 Kudos
TomKearns
Occasional Contributor II
I was hoping there was an easier answer (like a button to check).  I only need to run the model about 100 times and am not sure writing the script would be time efficent.  There is another section of the model that also needs to use the input file to go grab another file so that may be the best solution though.  This way I could just use the same code to call to both.
0 Kudos
curtvprice
MVP Esteemed Contributor
I was hoping there was an easier answer (like a button to check).


You can use the Parse Path tool to extract the name of an input, then use that model variable in the output file name as something like "out_%base name%.shp".
0 Kudos
TomKearns
Occasional Contributor II
That worked perfectly. 

Now I just need to figure out how to split up my file name (an 8 digit number) using python to call a file half way through the script.

12345678 needs to become C:/Temp/12/34/56/78

The new file is an input for a spatial join so parsing doesn't seem to work since it only produces strings.
0 Kudos
curtvprice
MVP Esteemed Contributor
Now I just need to figure out how to split up my file name (an 8 digit number) using python to call a file half way through the script.

12345678 needs to become C:/Temp/12/34/56/78


You could use this python expression inside the Calculate Value tool. All modelbuilder element values are strings so you can can slice them up using string slicing syntax:

"C:/TEMP/{0}/{1}/{2}/{3}".format("%name%"[:2],"%name%"[2:4], "%name%"[4:6], "%name%"[6:8])


Python slice addresses work like this:

0---1---2---3
  a   b   c


[:2] is "ab"
[1:3] is "bc"
0 Kudos