ImportToolbox (arcpy)

摘要

将指定的工具箱导入到 ArcPy 中,以便访问工具箱中的相关工具。

讨论

默认情况下,可在脚本中访问任何核心 ArcGIS 工具箱,但对于自定义工具箱或第三方工具箱,必须使用 ImportToolbox 来添加它们以便在脚本中使用。

可在多个不同的文件夹或地理数据库中找到其他工具箱,这些工具箱的来源可能各不相同;它们可能是您个人创建的工具箱,或者是您所在组织内部创建的工具箱,也可能是从“地理处理资源中心”等站点下载的工具箱。在任何情况下,将这些工具箱用作 Python 中的工具之前,需要将其一步导入到 ArcPy 中。

还可使用分号分隔符添加服务器工具箱。

Server

语法

Internet ArcGIS for Server

URL;服务名称;{用户名};{密码}

了解有关在 Python 中使用地理处理服务的详细信息

语法

ImportToolbox (input_file, {module_name})
参数说明数据类型
input_file

The geoprocessing toolbox to be added to the ArcPy site package.

String
module_name

If the toolbox does not have an alias, the module_name is required.

When a tool is accessed through the ArcPy site package, the toolbox alias where the tool is contained is a required suffix (arcpy.<toolname>_<alias>). Since ArcPy depends on toolbox aliases to access and execute the correct tool, aliases are extremely important when importing custom toolboxes. A good practice is to always define a custom toolbox's alias. However, if the toolbox alias is not defined, a temporary alias can be set as the second parameter.

String
返回值
数据类型说明
Module

返回导入的模块。

如果需要,可从模块的 __all__ 属性访问工具名称。

代码实例

ImportToolbox 示例

导入地理处理工具箱以在 ArcPy 中使用。

import arcpy

# Import custom toolbox
#
arcpy.ImportToolbox("c:/tools/My_Analysis_Tools.tbx")

try:
    # Run tool in the custom toolbox.  The tool is identified by 
    #  the tool name and the toolbox alias.
    #
    arcpy.GetPoints_myanalysis("c:/data/forest.shp")
except:
    print arcpy.GetMessages(2)

相关主题

9/15/2013