arcpy.AddMessage("Something...") message = arcpy.GetMessages() print message # always empty
Creates a geoprocessing informative message (Severity=0) that can be accessed with any of the GetMessages functions.
import arcpy arcpy.AddMessage("Something...") arcpy.AddMessage("Blah...") cnt = 0 for message in arcpy.GetMessages(): cnt += 1 arcpy.AddMessage("Message {0} is '{1}'".format(cnt, message)) arcpy.AddMessage("arcpy.GetMessageCount() results in: {0}".format(arcpy.GetMessageCount()))
AddMessage (arcpy)
Summary
Creates a geoprocessing informative message (Severity=0) that can be accessed with any of the GetMessages functions.
What then does the documentation refer to ?
import arcpy fc = r'C:\Project\_Forums\ZonStatPol\test.gdb\Intersect' 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)) print arcpy.GetMessages()