Listing tools, toolboxes, and environment settings

Depending on which toolboxes are available, ArcPy might have access to several toolboxes, dozens of environment settings, and hundreds of tools. ArcPy has several appropriately named functions to return a list of tools (ListTools), environment settings (ListEnvironments), or toolboxes (ListToolboxes).

Learn more about the ListEnvironments functionLearn more about the ListToolboxes functionLearn more about the ListTools function

Each function has a wild card option and returns a list of name strings that can be looped through. The example below shows how to access available tools and print out their usage.

import arcpy

# Create a list of the conversion tools
#
tools = arcpy.ListTools("*_conversion")

# Loop through the list and print each tool's usage
#   e.g., 'Usage: merge <inputs;inputs...> <output> {field_mappings}'
#
for tool in tools:
    print arcpy.Usage(tool)

The following sample provides an approach for viewing environment settings in Python.

import arcpy
import string

environments = arcpy.ListEnvironments()

# Sort the environment list, disregarding capitalization
#
environments.sort(key=string.lower)

for environment in environments:
    # As the environment is passed as a variable, use Python's getattr 
    #   to evaluate the environment's value
    #
    envSetting = getattr(arcpy.env, environment)

    # Format and print each environment and its current setting
    #
    print "{0:<30}: {1}".format(environment, envSetting)

The following sample provides an approach for viewing current toolboxes in Python.

import arcpy 

# Print all current toolboxes
#   
for toolbox in arcpy.ListToolboxes():
    # Toolboxes are printed in the form of "toolbox_name(toolbox_alias)"
    print toolbox

Related Topics

3/3/2014