Résumé
Use system ID messages with a script tool.
Discussion
For script tools, you can create your own errors and warnings using the AddWarning and AddError functions. Alternatively, you can also use any of the standard error or warning messages using the AddIDMessage function.
However, to reuse a standard error or warning, you must first know the six-digit code. This will require some research on your part; you will have to search the descriptions found in the help to find the right six-digit code. Once you've identified an appropriate ID, make note of any additional information that needs to be included in the message, usually denoted as <value>.
Syntaxe
AddIDMessage (message_type, message_ID, {add_argument1}, {add_argument2})
Paramètre | Explication | Type de données |
message_type | Specifies the message severity.
| 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. Data type 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. Data type can be string, integer, or double. | Object |
Exemple de code
Add a message to a Python script tool. The Python sample below checks to see whether a feature class has been provided as input and, if not, uses the AddIDMessage function to return ID code 12 (000012: <value> already exists). The optional argument is used to substitute the feature class name into the message.
class overwriteError(Exception):
pass
import arcpy
in_feature_class = arcpy.GetParameterAsText(0)
out_feature_class = arcpy.GetParameterAsText(1)
try:
# If the output feature class already exists, raise an error
if arcpy.Exists(in_feature_class):
# Raise a custom exception
raise overwriteError(out_feature_class)
else:
arcpy.CopyFeatures_management(in_feature_class, out_feature_class)
except overwriteError as err:
# Use message ID 12, and provide the output feature class
# to complete the message.
arcpy.AddIDMessage("Error", 12, str(err))
Rubriques connexes
Vous avez un commentaire à formuler concernant cette rubrique ?