AddIDMessage (arcpy)

Resumen

Allows you to use system messages with a script tool. A list of messages and IDs that can be used are provided under Understanding geoprocessing tool errors and warnings.

Debate

Geoprocessing errors and warnings are returned from geoprocessing tools with a six-digit code and a text message. Every error and warning has a corresponding description page in the desktop help system. This page contains both a detailed description of the error and possible solutions for the error. In tool dialog boxes, the Python window, and the Results window, the ID code is a link that, when clicked, takes you to a description page.

Sintaxis

AddIDMessage (message_type, message_ID, {add_argument1}, {add_argument2})
ParámetroExplicaciónTipo de datos
message_type

The message type defines whether the message will be an error, warning, or informative. Valid message types are:

  • ERRORAdds an error message to the tool messages.
  • INFORMATIVEAdds an informative message to the tool messages.
  • WARNINGAdds a warning message to the tool messages.
String
message_ID

The message ID allows you to reference existing messages for your scripting errors and warnings.

Integer
add_argument1

Depending on which message ID is used, an argument may be necessary to complete the message. Common examples include dataset or field names. Datatype can be string, integer, or double.

Object
add_argument2

Depending on which message ID is used, an argument may be necessary to complete the message. Common examples include dataset or field names. Datatype can be string, integer, or double.

Object

Ejemplo de código

AddIDMessage example

Add a message to a Python script tool.

class overwriteError(Exception):
    pass

import arcpy

inFeatureClass  = arcpy.GetParameterAsText(0)
outFeatureClass = arcpy.GetParameterAsText(1)

try:
    # If the output feature class already exists, raise an error
    #
    if arcpy.Exists(inFeatureClass):
        # Raise a custom exception
        #
        raise overwriteError(outFeatureClass)
    else:
        arcpy.CopyFeatures_management(inFeatureClass, outFeatureClass)

except overwriteError as e:
    # Use message ID 12, and provide the output feature class
    #    to complete the message.
    #
    arcpy.AddIDMessage("Error", 12, str(e))

Temas relacionados

9/11/2013