arcpy - new line in geoprocessing dialog window

6152
18
Jump to solution
04-14-2015 12:52 AM
MarkWisniewski
New Contributor III

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?

Tags (1)
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

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

View solution in original post

18 Replies
DanPatterson_Retired
MVP Emeritus

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)

MarkWisniewski
New Contributor III

Dan,

It appears \n isn't supported, I tried it in both statements above.

0 Kudos
DanPatterson_Retired
MVP Emeritus

you enclosed it in double quotes and used the + to concatenate them ? as in the following

arcpy.AddMessage("Hello" + "\n")

0 Kudos
MarkWisniewski
New Contributor III

Sure did;

Error 000576: Script associated with this tool does not exist.

0 Kudos
DanPatterson_Retired
MVP Emeritus

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

MarkWisniewski
New Contributor III

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

0 Kudos
DanPatterson_Retired
MVP Emeritus

just remove the...  "\n" +   ... if you are using AddMessage in a loop

MarkWisniewski
New Contributor III

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?

0 Kudos
DanPatterson_Retired
MVP Emeritus

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

0 Kudos