HOW TO
In some scenarios it is often easier to call a model within ModelBuilder using a Python script rather than converting the entire model to a Python script. Before calling the model, a custom toolbox must be added to the Python script as models are stored in a custom toolbox. For more information, refer to ArcGIS Desktop: Adding and connecting data and tools.
To call a model in a Python script, use the arcpy.AddToolbox() function to add the custom toolbox. Then call the model by either referencing the toolbox in a parameter, or call the model directly using the alias of the toolbox. The following steps describe how to do so:
tbx = arcpy.AddToolbox("C:/Temp/MyToolbox.tbx")
tbx.Sample1()
arcpy.Sample1_SampleMyTools()
Note: It is a best practice to add an alias name to the toolbox. The alias cannot contain spaces or special characters, such as an underscore (_).
If a model requires user input, create a variable in the Python script and refer the input shapefile location as the argument to the model parameter. For example, the following code sample passes the input feature class into the copy features tool within the model.
inFC = "C:/Temp/input.shp" tbx.Model(inFC)
Get help from ArcGIS experts
Download the Esri Support App