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"
Thank you all for your information on this.
here is what i finally went with.
imported arcpy,os
from subprocess import *
then i ran 4 child scripts after i converted each model to a script. i then called each script as a child script, had log findings embeded in the script to report back success
here is the script that i used in case any others run into this. this works!!! and it generates a log for you.
import arcpy, time, os, sys
from subprocess import *
arcpy.env.overwriteOutput = False
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"C:\UGM_Projected\Scripts\TEST_1_" + Date + ".txt", 'w')
Generate = open(r"C:\UGM_Projected\Scripts\TEST_1_" + Date + ".txt", 'w')
Generate.write("Script Started At: " + str(Date) + " " + str(Time) + "." + "\n")
#run child script 1
p = Popen([r"C:\UGM_Projected\Scripts\UDF_FeatureclasstoSHP.py", "ArcEditor"], shell=True, stdin=PIPE, stdout=PIPE)
output = p.communicate()
print output[0]
Generate.write("Success!! UDF_FeatureclasstoSHP.py" + str(Date) + " " + str(Time) + "." + "\n")
#run child script 2
p = Popen([r"C:\UGM_Projected\Scripts\SHP_FeatureClass.py", "ArcEditor"], shell=True, stdin=PIPE, stdout=PIPE)
output = p.communicate()
print output[0]
Generate.write("Success!! SHP_FeatureClass.py" + str(Date) + " " + str(Time) + "." + "\n")
#run child script 3
p = Popen([r"C:\UGM_Projected\Scripts\Delete_SHP.py", "ArcEditor"], shell=True, stdin=PIPE, stdout=PIPE)
output = p.communicate()
print output[0]
Generate.write("Success!! Delete_SHP.py " + str(Date) + " " + str(Time) + "." + "\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())
Generate.write(str("Script Ended at " + str(lDate) + " " + str(lTime) + "." ))
Generate.close()
now = time.time()
print "Script Complete"