Using Python to Automate ModelBuilder Models

Discussion created by parkerw13 on Apr 16, 2013
I have about 50 models built in ModelBuilder that I will need to make small edits to and then rerun. Instead of running them right after I've made the edits I would like to make the edits and then run them all as a batch through a python script overnight. I've been exploring a simple script that allows you to run models through python but I don't get the same output as when I run the model in ModelBuilder. I've looked for more documentation but I can't find anything. I'm hoping someone can help me out; I am a beginner python user so while this seemed simple to start I've quickly run out of ways to fix it.

The script is just this:

import arcpy

arcpy.ImportToolbox(r"K:\Working\Parker_Bill\BDCP\HCP\Test_HabitatModel_Automate_20130416\HCP_ModelData.gdb\toolbox", "TBX")

  print arcpy.GetMessages(0)

  print arcpy.GetMessages(2)

It should just run the one model which would output 3 different feature classes and write the messages from the geoprocessing to the Python Shell window. It does write the messages, and they are the same as when I run the model in ModelBuilder but no feature classes are created. I've found that it seems the problem is the last steps of my model are adding fields and calculating fields, as when I remove these steps I get the last feature class created as part of the model (but still not the two intermediate ones), but if I add a calculate field to the end I then get no feature class output.

I had hoped this would be a simple solution but it is turning out not to be. Is there anyway I can change the script to make it create all the feature classes that I get when I run the model in ModelBuilder?