AddWarning

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

摘要

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

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

语法

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

要添加的警告消息。

String

代码示例

AddWarning 示例

向脚本工具添加自定义警告消息。

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.AddWarning("{0} has no features.".format(fc))
else:
    arcpy.AddMessage("{0} has {1} features.".format(fc, feature_count))

相关主题