Model results incorrect when not run in Model Builder

3430
3
Jump to solution
04-07-2015 07:11 AM
CherylTrine
Occasional Contributor II

I have a model which iterates through a dataset, renames the shapefiles in the dataset and puts the new name of the shapefile into a "source" field in the shapefile. (The new name, used both in Rename and Calculate Source, is  '%Name%_%Date%')

Rename_AddSource.png

When I run it in the Model Builder window, it runs fine.  When I run it outside of model builder as a tool, it renames the first file and incorrectly calculates "source" as the new name of the second file, and it renames, but doesn't put any source, in the second file and then errors out saying the first renamed file already exists (which it does because it already created it).

Why is it trying to rename the first file again?  And why is it putting the new name for one file into the source field for another file? I thought the iterator takes the first file, runs it through the rest of the model, then the second file, and so on.  At least that seems to be how it runs in Model Builder.

At any rate, how can I fix this.  I need to be able to run it as a tool outside of Model Builder.

0 Kudos
1 Solution

Accepted Solutions
JohannesBierer
Regular Contributor
0 Kudos
3 Replies
ScottMoyer
Occasional Contributor

Cheryl,

When a model is run as a tool intermediate data is deleted. That's probably occurring after the the first Rename, and everything gets messed up thereafter. My suggestion is to create two iterating models, one for Rename and one for Calculate, and then drag and drop them into a new model that will run both of them. Please let me know if this works as I haven't tried running two embedded models.

Scott

JohannesBierer
Regular Contributor
0 Kudos
CherylTrine
Occasional Contributor II

Guess that's why I am learning Python!

Thanks to both Johannes and Scott for your responses.  I think I'll go the Python route.

0 Kudos