AddIDMessage (arcpy)
摘要
可以通过脚本工具使用系统消息。了解地理处理工具的错误和警告信息下面列出了可用的消息和 ID 列表。
讨论
地理处理过程中错误和警告信息由地理处理工具返回,形式为一个六位数代码和一条文本消息。每个错误和警告在桌面帮助系统中都有对应的描述页面。该页面包含详细的错误描述以及针对该错误的可能解决方案。工具对话框、Python 窗口以及结果窗口中的 ID 代码是一个链接,用户单击它后会进入描述页面。
语法
参数 | 说明 | 数据类型 |
message_type |
The message type defines whether the message will be an error, warning, or informative. Valid message types are:
| 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 |
代码实例
向 Python 脚本工具添加消息。
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))