AddReturnMessage

Summary

Sets the return message of a script tool as an output message by index.

Discussion

There are times when you may want to return all messages from a tool you've called, regardless of message severity. Using the index parameter, AddReturnMessage will return a message from the last tool executed. The severity of the message (warning, error, and so on, is preserved).

Geoprocessing error numbers shown in the progress dialog box are hyperlinks to a help page that further describes the error. To enable hyperlinks for errors in your script, use the AddReturnMessage function instead of the AddError function, as follows:

import arcpy
try:    
    result = arcpy.GetCount_management("c:/data/rivers.shp")

except:    
    # Return Geoprocessing tool specific errors
    #
    for msg in range(0, arcpy.GetMessageCount()):
        if arcpy.GetSeverity(msg) == 2:
            arcpy.AddReturnMessage(msg)

Syntax

AddReturnMessage (index)
ParameterExplanationData Type
index

The message index.

Integer

Code Sample

AddReturnMessage example

Returns all messages from the last tool executed as script tool output messages.

import arcpy
from arcpy import env

# Set current workspace
#
env.workspace = "C:/Data/MyData.gdb"

# Call the buffer tool from the Analysis toolbox.
#
arcpy.Buffer_analysis("Roads", "RoadsBuff1000", "1000 feet")

# Return the resulting messages as script tool output messages
#
x = 0
messageCount = arcpy.GetMessageCount() 
while x < messageCount:
    arcpy.AddReturnMessage(x)
    x += 1

Related Topics


10/28/2011