Hi,
I am currently using;
arcpy.AddMessage(arcpy.GetMessages())
and
arcpy.AddMessage(fc)
to tell me the features that are being processed by the geoprocessing tool in my script. Is there a way to seperate these in the geoprocessing dialog window by a line spacing because it looks cluttered?
Solved! Go to Solution.
AddMessage only works in scripts associated with tools in ArcToolbox. That error message means that the script you are using isn't associated with a tool. If you are running a script outside of a tool in ArcToolbox, then you have to use the print statement. If I want to have messages appear both in Arctoolbox's output dialog and when I run a script stand alone, then I do the following
msg = "my message here"
msg2 = "another message"
print msg, "\n", msg2 ( or print('{}\n {}'.format(msg,msg2)) using the newer print statement"
arcpy.AddMessage(msg + "\n" + msg2)
so you will have to clarify where you are running this and include your script portion
arcpy.AddMessage(arcpy.GetMessages() + "\n")
and/ or
arcpy.AddMessage("\n" + fc + "\n")
where "\n" is the newline in python and you have to concatenate them in AddM***
for arcpy.GetMessages you might have to cycle through the list and add a newline to each entry
msgs = arcpy.GetMessages()
for msg in msgs:
arcpy.AddMessage(msg)
Dan,
It appears \n isn't supported, I tried it in both statements above.
you enclosed it in double quotes and used the + to concatenate them ? as in the following
arcpy.AddMessage("Hello" + "\n")
Sure did;
Error 000576: Script associated with this tool does not exist.
AddMessage only works in scripts associated with tools in ArcToolbox. That error message means that the script you are using isn't associated with a tool. If you are running a script outside of a tool in ArcToolbox, then you have to use the print statement. If I want to have messages appear both in Arctoolbox's output dialog and when I run a script stand alone, then I do the following
msg = "my message here"
msg2 = "another message"
print msg, "\n", msg2 ( or print('{}\n {}'.format(msg,msg2)) using the newer print statement"
arcpy.AddMessage(msg + "\n" + msg2)
so you will have to clarify where you are running this and include your script portion
Oops Dan,
My apologies, user error, I renamed a folder that was used for accessing the script in the toolbox. My error. Had to set filepath in script again.
arcpy.AddMessage ("\n" + fc) is kind of working but gets;
abc.shp
xyz.shp
123.shp
How can I make the list please?;
abc.shp
xyz.shp
123.shp
just remove the... "\n" + ... if you are using AddMessage in a loop
That works removing the "\n" in my loop, but I am after this affect;
Running script Clip...
abc.shp
xyz.shp
123.shp
The line space after "Running script Clip..."in the dialog box and before the shapefile name. arcpy.AddMessage ("\n" + fc) inserts this space, but also a space between shapefile names. How can I remove the space between the shapefile names?
somewhere at the very beginning of your script just add a line which is a blank message
arcpy.AddMessage("")
if you didn't add the "running the clip script your self
then in the loop your message remains the same