Is This Content Helpful?
We're glad to know this article was helpful.
What are the advantages of calling a model directly from a Python script instead of exporting the model to a Python script?
Python scripts exported from ModelBuilder models may not work because complex parameters or tools available in ModelBuilder are unavailable in Python. For more information about exporting a Python script from ModelBuilder, refer to the following web help document, ArcGIS Desktop: Exporting a model to a Python script.
There are several reasons calling a model from a Python script is recommended instead of calling a Python script exported from ModelBuilder:
def createScript(): import os tbx_path = raw_input("Full path to toolbox: ") tbx_alias = raw_input("What is the alias of your toolbox?\n (can be found in the tbx properties) ") modelname = raw_input("What is the model name?\n (hint: this is not necessarily the same\n as the label and can be found in the model properties) ") outputLocation = raw_input("Where do you want the script located? ") outScript = open(os.path.join(outputLocation, "outScript.py"), "w") outScript.write("import arcpy\n") outScript.write('arcpy.ImportToolbox(r"' + tbx_path + '")\n') outScript.write('print "toolbox imported successfully"\n') outScript.write("arcpy." + modelname + "_" + tbx_alias + "()\n") outScript.write('print "model completed successfully"\n') outScript.close() if __name__ == '__main__': createScript()