ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

Defining a tool in a Python toolbox

  • Setting a tool class' __init__

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

Tool methodRequired/OptionalDescription

__init__

Required

Initializes the tool class.

getParameterInfo

Optional

Defines the tool's parameters

isLicensed

Optional

Returns whether the tool is licensed to execute.

updateParameters

Optional

Called each time the user changes a parameter on the tool dialog box. After returning from updateParameters, geoprocessing calls its internal validation routine.

updateMessages

Optional

Called after returning from the internal validation routine. You can examine the messages created from internal validation and change them if desired.

execute

Required

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.

PropertyDescription

canRunInBackground

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.

Learn more about running custom tools in the background.

category

The name of the toolset in which the tool is located. A toolset is a way to organize tools within a toolbox.

description

The description for the tool.

label

The label is the display name for the tool as shown in the Catalog window.

stylesheet

To change the default stylesheet used for the tool. If unset, the default stylesheet is used.

Related topics

  • Defining parameters in a Python toolbox
  • Defining parameter data types in a Python toolbox
  • What is a Python toolbox?

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2021 Esri. | Privacy | Legal