I recently came across a post about changing "the default error color in python" and was interested in doing something similar with Arcpy's AddMessage, AddWarning, and/or AddError functions. A few older posts like arcpy.AddMessage Formatting were made on Esri's site claiming that it's not possible, though they are quite a bit old.
Has there been any updates or workaround solutions?
I would assume that the message functions have some sort of html text coloring schema that they are following and are pulled from some file. Not sure if that comes from another python library, an OS setting, something Esri specifically built, etc.
If in fact AddMessage, AddWarning, AddError text color cannot be changed, would it be feasible to write a custom function or class that would be able to do this or is this a foundational issue with the processing dialog box?
Using ArcPy Pro.
-
Are you trying to do this using ArcPy with ArcGIS Pro or ArcPy with ArcMap? It may be the same answer for both but focusing on the former will be important when asking for an enhancement or lifting of a software limitation at ArcGIS Ideas.PolyGeo– PolyGeo ♦2023年10月20日 05:26:41 +00:00Commented Oct 20, 2023 at 5:26
-
ArcPy with ArcGIS Pro would be preferred. I'll update my post with that info.Binx– Binx2023年10月20日 17:04:02 +00:00Commented Oct 20, 2023 at 17:04
-
I regularly develop python code to be run as script tools so use the messaging system that arcpy provides to write messages to the dialog box. I know of now way to alter the colour of the messages.Hornbydd– Hornbydd2023年10月21日 00:19:48 +00:00Commented Oct 21, 2023 at 0:19
-
@Hornbydd sorry I am having a hard time reading your comment. Are you saying just print everything to the terminal and change the color there (like what Berend has answered below)? The print statements are necessarily for me, but others that are using the tool. So keeping everything in the Dialog box is preferred.Binx– Binx2023年10月22日 23:48:34 +00:00Commented Oct 22, 2023 at 23:48
-
1No I'm just agreeing with you. You have no control over the text colour when writing to the message dialog.Hornbydd– Hornbydd2023年10月23日 09:26:56 +00:00Commented Oct 23, 2023 at 9:26
2 Answers 2
It depends on where you want to see colors, in a text editor, in the console, in ArcGIS desktop?
Some text editors support coloring based on text content, either native or with a plugin.
For consoles that support Ansi escape sequences, you could use those in the output. For instance, arcpy.AddMessage("\u001B[31mRed\u001B[0m")
will output text in red.
-
I'm looking for the ArcGIS process dialog box.Binx– Binx2023年10月20日 17:09:24 +00:00Commented Oct 20, 2023 at 17:09
Just was informed that colors can be used - not sure when this was updated. Check out the example below.