AddError

此 ArcGIS 2.7 文档已 存档,并且不再对其进行更新。 其中的内容和链接可能已过期。 请参阅最新文档

描述

向脚本工具或 Python 工具箱工具的消息中添加自定义错误消息(严重性为 2)。

运行工具时,arcpy 完全知晓调用该工具的应用程序。其中一个主要作用是您可以在 Python 中写入消息,且您的消息会自动出现在工具对话框、历史记录和 Python 窗口中。

语法

AddError (message)
参数说明数据类型
message

要添加的错误消息。

String

代码示例

AddError 示例

添加自定义地理处理错误消息。

import arcpy
fc = arcpy.GetParameterAsText(0)
# Get the count from GetCount's Result object
feature_count = int(arcpy.GetCount_management(fc).getOutput(0))
if feature_count == 0:
    arcpy.AddError("{0} has no features.".format(fc))
else:
    arcpy.AddMessage("{0} has {1} features.".format(fc, feature_count))

相关主题