arcpy.AddMessage not working in python window

8797
7
05-15-2012 03:17 PM
by Anonymous User
Not applicable
Hello all

this's a very frustrating problem: the addMessage function is not working for me in the Python Window. It works in a toolbox message window or in an IDE like WingIDE... but not in the Python Window...

What is happening?

Thank you in advance

Jesús de Diego
Tags (2)
7 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Jesus,

If you are using IDLE or PythonWin, you will want to use 'print'.  I use PythonWin so I use both 'print' and 'arcpy.AddMessage'.  That way I don't have to update any code when I run the script within ArcMap.  Ex:

print "Succeeded"
arcpy.AddMessage("Succeeded")
0 Kudos
MathewCoyle
Frequent Contributor
Or, if you have to do it a lot, why not function?

def printline(message):
    """printline(message)

        message(string):
       The message to be printed
    """
    print message
    arcpy.AddMessage(message)

printline("Hello World!")
0 Kudos
by Anonymous User
Not applicable
Thank you all

yes, these are alternative ways, but: why can't I use addMessage in the Python Window? Can i?

jesús de Diego
0 Kudos
MathewCoyle
Frequent Contributor
That is not was AddMessage was designed to do, so not currently no.

See here under "Messaging in a dual-purpose script"
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Writing_messages_in_script_tools/00150...
0 Kudos
by Anonymous User
Not applicable
Greetings to all

Mathew Thanks for your reply. However, I can not clarify this issue. These are the tests I've done using these two lines:

import arcpy
arcpy.AddMessage ("Hello")

- Run these two lines in the ArcMap "Python" Window. Does not show the message....
- Run these two lines in the Windows command line (cmd). It works. (Appears "hello")
- Save these two lines as a script, add as a Toolbox and run the tool. I have used the  ArcMap "Python" window, ArcToolbox (running the tool) and the Windows command line. In all three cases, it works. In the first case, the result appears in the output window (right of the Python window). In the second case, the result appears in the progress dialog box of the tool. In the third case shows the outcome in the command line.

But, according to the link you sent me, this function "AddMessage" should work if not used in a script "stand-alone", as in the case of the Windows command line ...

Surely I'm missing something ....

thank you in advance

Jesús de Diego
0 Kudos
JasonScheirer
Occasional Contributor III
Use the print statement, not the AddMessage functuion, for writing directly to the Python window. AddMessage is for running within geoprocessing tools, not for pushing text to the window of your Python interpreter.
0 Kudos
KimOllivier
Occasional Contributor III
Oddly I did notice that arcpy.AddMessage does print if you run the script from the CMD window!
Which is very frustrating if you have doubled up with print messages, you get the messages twice.
0 Kudos