Trouble shooting

javascript:void(0)

Contents:
  • 3 Macros
    • 3.1 Tools

Macros

Tools

print("Hello World!");

Anatomy of “Hello World!”

Let’s see more details of what the single line code we wrote is doing.

print() is a build-in macro function that requests ImageJ to take the content within the parenthesis and print that out in the "Log" window. This content, which we genearlly call the argument of the function, is an input value given to the function. The output of this function is the printed text in the Log window. Note that when a text is given as an argument, it must be surrounded by double quotes ("").

Where do we get information as such for other macro functions? The best reference for ImageJ macro functions is in the ImageJ web site 11http://rsbweb.nih.gov/ij/developer/macro/functions.html. For example, you could find definition of print("") function on the web site as quoted below:

    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 referred 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".

As print can do many things, its explanation is extraordinary long, but by carefully reading it, you will save time afterwards by the knowledge of wide spectrum of things that the print function can do e.g. directly save text as a file.

Macro can be saved as a file. In the editor, do [File -> Save]. Just save the file wherever you want in your file system. When you want to use the macro again, load the macro by [File > Open].

EXERCISE 1  

    Add another line "print("\\Clear");"before the first line (below, code 1.51. don’t forget the semi-colon at the end!).
    1//code 1.5
    2print("\\Clear");
    3print("Hello World!");
    (code/code01_51.ijm) Then test also another macro when you put the same line after "Hello World!". What happened? Any difference in the behavior?
    1//Code 1.76
    2print("Hello World!");
    3print("\\Clear");
    (code/code01_76.ijm) Answer: The first code prints "Hello World!", while the second code prints nothing. This is becaise print("\\Clear") is a command that clears the Log window. In the first code, “Hello World” is printed after the window clearing, and in the second case the Log window is wiped out right after the printing of “Hello World”. Effectively it looks like nothing has happened.

 

EXERCISE 2  

    Try modifying the third line in code 1.51 and check that the modified text will be printed in the "Log" window.