AddMessage

Summary

The AddMessage function adds an informative message (severity of 0) to the messages of a script tool or Python toolbox tool.

When a tool is run, an informative message can be accessed from the Geoprocessing pane, the geoprocessing history, and the list of messages when a tool is called from Python.

Discussion

In addition to message strings, the AddMessage function supports clickable links in the Geoprocessing pane using a JSON structure as follows:

  • element—A value of "content" defines a message container.
  • data—A list of strings and structured elements.
    • element—A value of "hyperlink" defines a hyperlink container.
    • data—The label shown for the URL.
    • link—The URL that will open when clicked.

Add an informative message that includes a clickable link.

import arcpy
import json

message_structure = {
    "element": "content",
    "data": [
        "For more information, see: ",
        {
            "element": "hyperlink",
            "data": "Esri",
            "link": "https://www.esri.com/"
        }
    ]
}

arcpy.AddMessage(f"json:{json.dumps(message_structure)}")

Syntax

AddMessage (message)
ParameterExplanationData Type
message

The informative message.

String

Code sample

AddMessage example

Add an informative message to a Python script tool.

import arcpy

fc = arcpy.GetParameterAsText(0)

# Get the count from GetCount's Result object
feature_count = int(arcpy.management.GetCount(fc)[0])

if feature_count == 0:
    arcpy.AddError("{0} has no features.".format(fc))
else:
    arcpy.AddMessage("{0} has {1} features.".format(fc, feature_count))

Related topics