For a while now we're running a script each night via task scheduler from which several custom models are being run.
In an effort to streamline the code and simplify adding more models in the future I'm attempting to create a list at the start of my script and calling them in a for loop.
import arcpy Toolbox= r"S:\GEOINFO\05_Tekenkamer\Marc\Test1" Models = ["TestDissolve","TestTerminals"] #Import Toolbox arcpy.ImportToolbox(Toolbox) #Run models for Model in Models: print ("Executing model " + str(Model)) try: arcpy.TestDissolve_Test1() print ("Executing model " + str(Model) + "succeeded") except: print ("An error occured") print("End of script")
The part where I'm stuck is the first line of the try block where I run the model. I'm trying to substitute the fixed part of 'TestDissolve' after arcpy. for the current Model in the list (Test1 is the alias of the toolbox).
The first thing I tried was phrasing it like 'arcpy.Model_Test1' but that gives an error that the model Model can't be found. I don't think you can compose it in a string and then run it, or at least I don't know how.
Another way to fix the issue of running multiple models could be just to run every model from the toolbox somehow but not all of them have to be run every day and some have to be run in a certain order so I didn't try that.
I'm not sure if I'm overlooking something obvious here or if it's even possible but I'm hoping anyone here can help me with this.
Some additional information: we're using ArcGis 10.3.1 (python 2.7) but we might be able to use python 3 for this on our server if that could solve the issue.
How can I call models with arcpy from a list of models?