AddReturnMessage

摘要

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

讨论

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)

语法

AddReturnMessage (index)
参数说明数据类型
index

The message index.

Integer

代码示例

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

相关主题


7/10/2012