arcpy.AddError的作用是,在arcgis py脚本中,中止程序 并向消息框报错相关信息,算是主动抛出异常。
arcpy.AddMessage的作用是,在arcgis py脚本中,将指定信息输入到消息框。
代码实例:
判断输入的图层里面的要素数量,如果要素为0个,则中止程序并报错
如果要素不为0个,则向消息框提示相关信息
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))