Call a ModelBuilder model in a Python script

相关信息
Article ID: 46226
Software:
ArcGIS for Desktop Advanced 10.2, 10.2.1, 10.3, 10.3.1, 10.4, 10.2.2
Platforms:
Windows Windows 8, Windows 8.1, Windows 10

问题描述
In some situations it is often easier to call a ModelBuilder model in a Python script rather than converting an entire model to a Python script. This technical article describes how to do this.
已邀请:

易智瑞技术支持

赞同来自:

解决方案
ModelBuilder models are stored in a custom toolbox, and to call them within the Python script the arcpy.AddToolbox() function is required.

1. Create a variable referencing the toolbox. 
tbx = arcpy.AddToolbox("C:/Temp/MyTools.tbx")

2. Call the model using the variable created in the previous step. In this example 'Model' is the name of the model.
tbx.Model()
 
 The model can also be called up using the alias name for the toolbox (arcpy.toolbox_alias). It is a best practice to add an alias name to the toolbox.
3. If a model requires a user input, create a variable in the Python script and pass that as the argument to the model parameter. For example, the following code sample passes an input feature class into the copy features tool in the model.
inFC = "C:/Temp/input.shp"

tbx.Model(inFC)

其它相关参考
  1. Arcpy AddToolbox


创建及修改时间
Created: 2/2/2016 Last Modified: 3/4/2016
原文链接
http://support.esri.com/en/kno ... 46226

要回复问题请先登录注册