Select to view content in your preferred language

Enable arcpy messaging to include hyperlinks in the message

206
2
07-10-2024 04:58 PM
Status: Open
DuncanHornby
MVP Notable Contributor

So a question was asked way back in 2012 about adding hyperlinks in error messaging. 12 years have passed, ArcPro is the main desktop application and this has not come to pass so I'm asking now if this can be considered as an idea.

Currently my error messaging might be something like this:

arcpy.AddError("Some error, you need to go to Amazon!")

 

What I would like to be able to do is something like this, but this simply prints everything:

arcpy.AddError('Some error, you need to go to <a href="https://www.amazon.co.uk">Amazon!</a>')

 

In my use case scenario I would replace the URL with a URL to an error page for an online manual.

2 Comments
DavidWynne

Hi @DuncanHornby,

There is an existing pathway for this that you might be interested in.

Internally, we do have some additional message features that were created for a subset of Pro teams that develop geoprocessing tools. Supporting links was part of that. It's organized as a json type of structure (like below) that you can use with the arcpy message functions. 

Currently, it's not officially supported, and there is potential for this to change in the future.

msg = """json:
    [{"element": "content",
      "data": ["This is my link: ", 
               {"element": "hyperlink", 
                "data": "Esri", 
                "link": "https://www.esri.com/"}]}]"""

arcpy.AddMessage(msg)

 

DavidWynne_0-1720821956786.png

Hope this helps,
-Dave

DuncanHornby

Dave,

This is great news but I feel cautious to use it as you say its "not officially supported", which to me could indicate that it could be removed without warning as well as becoming official.

Now this is just me but I find using json horrible, it's just all brackets within brackets with colons upon colons to me! I have always found json hard to decypher. So if the Pro team were to consider to make this a supported feature (which would be great!) then I ask them to consider an easier approach like a <a></a> or maybe some sort of object based approach?  For example a geoprocessing tool returns a result object which one can tap into the various properties. May be the AddMessage can take of a sort of message object? Just an idea.

Anyway this I think would be really useful and surprised that it's not in the documentation, so at the minimum you could suggest to the team to expand the help documentation to show off this very useful property.

Thanks!

Duncan