Tools are added to a .pyt as classes. Each tool class should include at a minimum an __init__ and execute method. Optionally, getParameterInfo, isLicensed, updateParameters, and updateMessages methods can be used to add additional control to the behavior of the tool.
Methods used to define a working tool class
Initializes the tool class.
Defines the tool's parameters
Returns whether the tool is licensed to execute.
Called each time the user changes a parameter on the tool dialog box. After returning from updateParameters, geoprocessing calls its internal validation routine.
Called after returning from the internal validation routine. You can examine the messages created from internal validation and change them if desired.
The tool's source code.
Setting a tool class' __init__
The __init__ method in a tool class is a standard Python class initialization method. For a tool in a Python toolbox, the __init__ method is used to set properties of the tool, including the tool's label and description. The tool's name is established by the name of the class itself (in the example, below, the tool name is CalculateSinuosity).
The __init__ method establishes tool properties such as the label and description. Below, a tool named CalculateSinuosity is created.
class CalculateSinuosity(object): def __init__(self): self.label = "Calculate Sinuosity" self.description = "Sinuosity measures the amount that a river meanders within its valley, " + \ "calculated by dividing total stream length by valley length."
The following properties can be set in a tool's __init__ method.
If canRunInBackground is unset or set to True, the tool will respect the current Background Processing setting in the Geoprocessing Options dialog.
If set to False, the tool will always run in the foreground, overriding the Background Processing setting in the Geoprocessing Options dialog.
The name of the toolset in which the tool is located. A toolset is a way to organize tools within a toolbox.
The description for the tool.
The label is the display name for the tool as shown in the Catalog window.
To change the default stylesheet used for the tool. If unset, the default stylesheet is used.