Select to view content in your preferred language

Model results incorrect when not run in Model Builder

3883
3
Jump to solution
04-07-2015 07:11 AM
CherylTrine
Frequent Contributor

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
3 Replies
ScottMoyer
Deactivated User

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
Frequent Contributor
0 Kudos
CherylTrine
Frequent Contributor

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