ArcGIS for Desktop

  • Documentation
  • Pricing
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS for Desktop

A complete professional GIS

ArcGIS for Server

GIS in your enterprise

ArcGIS for 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
  • Pricing
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

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?
Feedback on this topic?

ArcGIS for Desktop

  • Home
  • Documentation
  • Pricing
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
© Copyright 2016 Environmental Systems Research Institute, Inc. | Privacy | Legal