AddMessage

摘要

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

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

语法

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

要添加的消息。

String

代码示例

AddMessage 示例

向 Python 脚本工具添加自定义信息性消息。

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))

相关主题