AddToolbox
汇总
将指定的工具箱导入到 ArcPy 中,以便访问工具箱中的相关工具。
注:
此函数相当于 ImportToolbox 函数。
讨论
默认情况下,可在脚本中访问任何核心 ArcGIS 工具箱,但对于自定义工具箱或第三方工具箱,必须使用 ImportToolbox 来添加它们才能在脚本中使用。
在多个文件夹或地理数据库中可能包含其他工具箱,这些工具箱的来源可能各不相同;它们可能是您创建的工具箱,或者是您所在组织内部创建的工具箱,也可能是从 ArcGIS Online 或其他站点下载的工具箱。 在任何情况下,要将这些工具箱用作 Python 中的工具,必须将其导入到 ArcPy 中。
地理处理服务也可以使用分号分隔符导入。
|
参数 |
语法 |
|---|---|
|
|
|
AddToolbox 还支持通过使用 ArcGIS Server 连接 (.ags) 文件来使用受保护的 ArcGIS Online 服务。 使用 .ags 文件可将凭据存储并隐藏在文件中。
要允许任何 arcgis.com 用户访问您的工具,请使用 UseSSOIdentityIfPortalOwned 关键字。 如未登录,执行 AddToolbox 时,系统将提示 登录 对话框;如已登录,可成功执行此操作。
import arcpy
tbx = "http://logistics.arcgis.com/arcgis/services;World/ServiceAreas;UseSSOIdentityIfPortalOwned"
arcpy.AddToolbox(tbx)
arcpy.ServiceAreas.GenerateServiceAreas()
注:
将使用 登录 对话框运行独立 Python 文件。
如果先前已获取令牌,则该令牌也可与 AddToolbox 组合使用。
import arcpy
token = 'sadsa213d2j32jsdw02dm2'
referrer = 'http://www.arcgis.com/'
tbx = 'http://logistics.arcgis.com/arcgis/services;' + \
'World/ServiceAreas;token={};{}'.format(token, referrer)
arcpy.ImportToolbox(tbx)
result = arcpy.ServiceAreas.GenerateServiceAreas()
语法
AddToolbox(input_file, {module_name})
| 参数 | 说明 | 数据类型 |
|---|---|---|
|
input_file |
The geoprocessing toolbox that will be accessed from ArcPy. |
String |
|
module_name |
If the toolbox does not have an alias, the When a tool is accessed through the ArcPy site package, the toolbox alias where the tool is contained is a required suffix ( |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
Module |
返回导入的模块。 如果需要,可从模块的 |
代码示例
添加指定工具箱。
import arcpy
# Import custom toolbox
arcpy.AddToolbox("c:/tools/My_Analysis_Tools.atbx")
try:
# Run tool in the custom toolbox. The tool is identified by the tool name
# and the toolbox alias.
arcpy.myanalysis.GetPoints("c:/data/forest.shp")
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))