ImportToolbox

摘要

Imports the specified toolbox into ArcPy, allowing for access to the toolbox's associated tools.

讨论

While any of the core ArcGIS toolboxes are accessible by default in a script, your own custom or third-party toolboxes must be added using ImportToolbox to use them in a script.

Other toolboxes may be found in any number of different folders or geodatabases, and may have many different origins; they may be toolboxes you have personally created, or are toolboxes created internally by your organization, or are toolboxes you have downloaded from sites like the Geoprocessing Resource Center. In any case, these toolboxes need to be imported into ArcPy in a one-step process before they can be used as tools in 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.

提示提示:

The best practice is to assign an alias when first creating the toolbox rather than using ImportToolbox to assign a temporary one that will only be applicable in Python.

String

代码示例

ImportToolbox example

Import geoprocessing toolbox for use in 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)

相关主题


7/10/2012