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

environments = arcpy.ListEnvironments()

# Sort the environment list, disregarding capitalization

for environment in environments:
    # Use Python's eval function to evaluate an environment's value
    envSetting = eval("arcpy.env." + environment)

    # Format and print each environment and its current setting
    print "%-30s: %s" % (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