Login  Register

Re: Macro "call" mechanism unusual "feature" / Accessing image properties

Posted by Wayne Rasband on Mar 16, 2008; 1:12am
URL: http://imagej.273.s1.nabble.com/select-without-clicking-for-clearSelection-of-TextPanel-tp3696867p3696869.html

This is a "feature" that allows you to enter an expression or  
function call and have the output displayed in the log window by  
pressing ctrl-r (Macros>Run Macro). For example, enter

    2+2
    sqrt(2)
    getInfo("java.version")
    call("ij.IJ.freeMemory")

press ctrl-r (Macros>Run Macro) and

    4
    1.4142
    1.5.0_07
    5421K of 710MB (<1%)

is displayed in the Log window. Press ctrl-e (Macros>Evaluate Line)  
and the last expression or function entered is evaluated.

-wayne

On Mar 15, 2008, at 5:30 PM, Joachim Wesner wrote:

> Hi list,
>
> while writing a simple class that allows to access general image  
> properties
> via the "call" mechanism to a static Java method, (If anybody  
> interested, I
> attach it) I noted an unusual "feature"
> of that call mechanism:
>
> If you call a method that returns a string (which in my case may  
> only be a
> status value if the property setting succeded or not), but do NOT  
> use the
> result in the macro,
>  i.e. only do (in my case)
>
> call ("ImpProps.setProperty", "foo", "bar");
>
> instead of
>
> result=call ("ImpProps.setProperty", "foo", "bar");
>
> the "Log" window always comes up, showing that otherwise ignored  
> result
> string. Is this intended? Useful?
>
>
> Sincerely
>
> Joachim
>
>
> import ij.*;
>
> /**
>  * This simple class can be called from an ImageJ macro via the "call"
> mechanism to
>  * get and set the (string) properties of the active image  
> (ImagePlus).
>  *
>  * call("ImpProps.setProperty", "<key>", "<value>");
>  *        set property <key> to <value>, returns <value> if  
> successful,
>  *        "" otherwise (no active image)
>  *
>  * call("ImpProps.getProperty", "<key>");
>  *        returns value of property <key> if set, "" otherwise (not  
> found
> or no active image)
>  *
>  * @see    ij.ImagePlus#setProperty
>  * @see    ij.ImagePlus#getProperty
>  *
>  * @author Joachim Wesner
>  * @author Leica Microsystems CMS GmbH
>  * @author [hidden email]
>  * @version 2008-3-15
>  *
>  * This class can be compiled with ImageJ's Plugins>Compile and Run
> command.
>  */
>
> public class ImpProps {
>
>           public static String getProperty(String arg1) {
>                    ImagePlus imp = IJ.getImage();
>                    if (imp == null)
>                              return "";
>                    Object prop = imp.getProperty(arg1);
>                    if (prop != null && prop instanceof String)
>                              return (String)prop;
>                    else
>                              return "";
>           }
>
>           public static String setProperty(String arg1, String arg2) {
>
>                    ImagePlus imp = IJ.getImage();
>                    if (imp == null)
>                              return "";
>                    imp.setProperty(arg1, arg2);
>                    return arg2;
>
>           }
> }
>
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________