AnsweredAssumed Answered

Run Model Builder models thru Python.

Question asked by lelabach on Jun 25, 2015
Latest reply on Aug 18, 2015 by blake.terhune

i have 4 models that i created i am trying to run them thru python to get them to execute one at a time. i have two ways i want to try to do this. a. have python run the models ( to no success as of yet)

b. export each model out as a script and have a master script that calls on 4 scripts to run one after the other until all 4 have ran in sequence.

i am very new to this and would love any help.

here is what i have so far. and here are my errors

ERROR

Traceback (most recent call last):

  File "F:\GIS\Python_Scripts\GLE_BIS_Silverlight_Overwrite\Archive\Delete_Temp_Holding.py", line 16, in <module>

    arcpy.ImportToolbox("F:/GIS/Python_Scripts/GLE_BIS_Silverlight_Overwrite/GLE_BIS.tbx")

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\__init__.py", line 90, in ImportToolbox

    return import_toolbox(input_file, module_name)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\toolbox_code.py", line 441, in import_toolbox

    mymodule = generate_toolbox_module(toolbox, None, False, False, False, module_name, use_alt_alias)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\toolbox_code.py", line 416, in generate_toolbox_module

    'exec')

  File "F:\GIS\Python_Scripts\GLE_BIS_Silverlight_Overwrite\GLE_BIS.tbx", line 63

    def SHP-BIS():

           ^

SyntaxError: invalid syntax

 

 

Script

import arcpy, time, os, sys

 

 

Date = time.strftime("%m-%d-%Y", time.localtime())

Time = time.strftime ("%I:%M:%S :p",time.localtime())

LogFile = file(r"F:\GIS\Python_Scripts\Logs\GLE to BIS PROJECTION AND TRANSFER_" + Date + ".txt", 'w')

output = open(r"F:\GIS\Python_Scripts\Logs\GLE to BIS PROJECTION AND TRANSFER_" + Date + ".txt", 'w')

 

 

arcpy.ImportToolbox("F:/GIS/Python_Scripts/GLE_BIS_Silverlight_Overwrite/GLE_BIS.tbx")

 

# Local variables:

output.write("Script Started At: " + str(Date) + " " + str(Time) + "." + "\n" + "Start Delete Process" +"\n")

 

# Process: Delete Temp Holding Shapefiles

arcpy.DeleteTempHolding_GLE_BIS()

try:

     # Process: Delete Temp Holding Shapefiles

        if arcpy.DeleteTempHolding_GLE_BIS():

            output.write("Delete of Temporary files SUCCESS","\n")

except:

    output.write("Delete of Temporary files FAIL","\n")

 

output.write("END OF SCRIPT","\n")

 

# reset date and time from when  started

lDate = time.strftime("%m-%d-%Y", time.localtime())

lTime = time.strftime("%I:%M:%S %p",time.localtime())

 

# write to log and close

output.write(str("GLE to BIS Script Ended at  " + str(lDate) + " " + str(lTime) + "." + "\n"))

output.close()

 

now = time.time()

 

print "Script Complete"

Outcomes