Python 工具箱模板

创建 Python 工具箱时,可使用以下模板组建工具箱。 此代码将创建一个 Python 工具箱,其中包含一个名为 Toolbox 的工具箱类,以及一个名为 Tool 的工具。 应将 Tool 类重命名,而且可复制并编辑该类以便在 Python 工具箱中创建其他工具。 工具名称和工具箱别名的开头必须为字母(a-z、A-Z),并且只能由字母和数字 (0-9) 组成。 不允许使用空格和特殊字符(例如,_、!、@、#、$、%、-)。

或者,复制以下代码并将其粘贴到新的 .pyt 文件中。

# -*- coding: utf-8 -*-

import arcpy


class Toolbox:
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Toolbox"
        self.alias = "toolbox"

        # List of tool classes associated with this toolbox
        self.tools = [Tool]


class Tool:
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = ""

    def getParameterInfo(self):
        """Define the tool parameters."""
        params = None
        return params

    def isLicensed(self):
        """Set whether the tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter. This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        return

    def postExecute(self, parameters):
        """This method takes place after outputs are processed and
        added to the display."""
        return

相关主题