Select to view content in your preferred language

How to print Web Tool output messages

340
0
03-10-2026 12:37 PM
JasonBennett
Regular Contributor

I am publishing a Web Tool with ArcGIS Notebooks. I need to print messages for the user to see so that they will understand the results of running the tool and what actions to take next. This works well with an ArcGIS Pro tool with AddMessage() or any other python tool with print().

However, when running a Web Tool neither print() or AddMessage() appear on the messages tab in this output window:

image.png

It will display system warnings, but not my custom messages.

I can create output parameters in the tool, so I created an output string. The Notebook automatically generated some code to use for the output. Using that code, I've been trying to produce a readable output. The best I've come up with so far using this code:

# Inserted snippet writes output parameter file for web tool execution
import os
#result = "\r\n".join(messages)
#print(result)
def output_message(result: str):
    # Only run this snippet during web tool execution when env variable "ENB_JOBID" will be present
    if "ENB_JOBID" in os.environ:
        out_param_name = "result"
        out_param_file = os.path.join(
            os.environ["ENB_JOBID"], "value_" + out_param_name + ".dat")
        with open(out_param_file, "a") as writer:
            writer.write(str(result) + "\r\n")

 

It produces this:

image.png

One long text string with no breaks. I've attempted to create breaks (you'll see the "\r\n" in my latest).

I'm calling output_messages in place of print() and it appends each message to the output file.

It needs to look like this:

image.png

Does anyone have any suggestions on how to do this?

0 Replies