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...

Writing messages in script tools

  • Example of adding messages

When a tool is run, ArcPy is fully aware of the application it is called from. One major effect of this is that you can write messages in Python and your messages automatically appear on the progress dialog box, the tool's result in the Results window, and the Python window. It also means that any model or script tool that calls your tool has access to the messages you write.

Learn more about messaging in Understanding messaging in script tools

During execution of a tool, messages are written that can be retrieved with geoprocessing functions. The four ArcPy functions for writing messages are as follows:

  • AddMessage(message)—For general informative messages (severity = 0)
  • AddWarning(message)—For warning messages (severity = 1)
  • AddError(message)—For error messages (severity = 2)
  • AddIDMessage(message_type, message_ID, add_argument1, add_argument2)—Used for both errors and warnings (The message_type argument determines severity.)

A call to AddIDMessage() displays a short message and the message ID, which is a link to an explanation about the cause of and solutions to the problem. When you add an error message using either AddError() or AddIDMessage(), the following occur:

  • Your script continues execution. It is up to you to add appropriate error-handling logic and stop execution of your script. For example, you might need to delete intermediate files or cursors.
  • Upon return from your script, the calling script or model receives a system error and execution stops.

Example of adding messages

In the example below, the input is evaluated, and if it contains no input features, an error message is added to the tool and an arcpy.ExecuteError exception is raised to end the tool.

import arcpy
input = arcpy.GetParameterAsText(0)
output = arcpy.GetParameterAsText(0)
       
# If the input has no features, add an error message, and raise
#  an arcpy.ExecuteError
if int(arcpy.GetCount_management(input)[0]) == 0:
    arcpy.AddError("{0} has no features.".format(input))
    raise arcpy.ExecuteError

Related Topics

  • Understanding messages in script tools
  • What is a script tool?
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