Clear log windows in a macro

Hi there,

is there a way to clear the log in a macro?
I have code my macro to show some results in the log window after processing one picture, but I wouldlike to clear the window after that so the next results, from the next picture, apprear as the only thing written in the log window.

thanks a lot for your help

Hi Dmajbs,

print("\\Clear")

is what you’re looking for. You could also use

print("\\Update:<text>")

which will clear the log window and update it with “text”.

D.

1 Like

Good day,

it’s always a good idea to consult the docs, i.e. here the ImageJ-macro functions:
https://imagej.nih.gov/ij/developer/macro/functions.html

There you’ll find:

print(string)
Outputs a string to the “Log” window. Numeric arguments are automatically converted to strings. The print() function accepts multiple arguments. For example, you can use print(x,y,width, height) instead of print(x+" “+y+” “+width+” "+height). If the first argument is a file handle returned by File.open(path), then the second is saved in the refered file (see SaveTextFileDemo).

Numeric expressions are automatically converted to strings using four decimal places, or use the d2s function to specify the decimal places. For example, print(2/3) outputs “0.6667” but print(d2s(2/3,1)) outputs “0.7”.

The print() function accepts commands such as “\Clear”, “\Update:” and “\Update:” (for n<26) that clear the “Log” window and update its contents. For example, print("\Clear") erases the Log window, print("\Update:new text") replaces the last line with “new text” and print("\Update8:new 8th line") replaces the 8th line with “new 8th line”. Refer to the LogWindowTricks macro for an example.

The second argument to print(arg1, arg2) is appended to a text window or table if the first argument is a window title in brackets, for example print("[My Window]", “Hello, world”). With text windows, newline characters ("\n") are not automatically appended and text that starts with “\Update:” replaces the entire contents of the window. Refer to the PrintToTextWindow, Clock and ProgressBar macros for examples.

The second argument to print(arg1, arg2) is appended to a table (e.g., ResultsTable) if the first argument is the title of the table in brackets. Use the Plugins>New command to open a blank table. Any command that can be sent to the “Log” window ("\Clear", “\Update:” , etc.) can also be sent to a table. Refer to the SineCosineTable2 and TableTricks macros for examples.

HTH

Herbie

Thanks a lot both of you!

Sorry Herbie, i did try to find something in the docs, but never occured to me to look at the “print” comand when actually looking how the clear the printed stuff… newbie errors I´m afraid.

By the way, I finally got my code doing what I want to do, which is a task quite specific (it set the scale depending on the magnification of the picture, as said in the filename, and then ask the user to draw the ROI in order to measure the area. Finally, it prints the results so you can just copy and paste them into excel.). Is this worth uplading somewhere, so it can be used by anyone, or it is just another code relevant only for the author?

Again, thank you very much indeed for your help!

Cheers

1 Like

@Dmajbs

Glad you got things working… just post your code here. That could be helpful to people down-the-road…

eta :slight_smile:

Great that everything works for you.

BTW, I simply searched the “ImageJ-macro functions”-page for “Clear”.
Actually, I never needed to clear the Log-window yet.

Regards

Herbie

Thanks a lot, I will upload it in a new thread with a proper explanation of what it does.

Again, thanks a lot for your help and patience (you Herbie above all!!)