Login  Register

Re: How to construct the ROI manager

Posted by Jan Eglinger on Aug 23, 2015; 4:28pm
URL: http://imagej.273.s1.nabble.com/How-to-construct-the-ROI-manager-tp5014113p5014117.html

Hi Avital,

 > rm = RoiManager();
 > returnedRm = rm.getInstance();

getInstance is a _static_ method of the RoiManager class, i.e. you don't
need to create an instance of RoiManager, just call the method like this:

     rm = RoiManager.getInstance()

See also here:
http://fiji.sc/Scripting_toolbox#Select_multiple_ROIs_from_ROI_manager_and_combine_them

Hope that helps,
Jan


On 23.08.15 11:04, Avital Steinberg wrote:

> Hi,
> I'm trying to count the number of objects in the roi manager in Javascript.
> I wrote the following code:
>
> importClass(Packages.ij.IJ);
> importClass(Packages.ij.plugin.frame.RoiManager);
> importClass(Packages.ij.io.OpenDialog);
> importClass(Packages.ij.io.DirectoryChooser);
> importClass(Packages.java.io.File);
> importClass(Packages.ij.gui.GenericDialog);
> importClass(Packages.ij.util.Tools);
> importClass(Packages.ij.plugin.Duplicator);
>
> IJ = IJ();
> rm = RoiManager();
> returnedRm = rm.getInstance();
> print("The returned rm is: " + returnedRm);
> var nObjects = rm.getCount();
> print("nObjects is: " + nObjects);
>
> And I get the following error message:
>
> javax.script.ScriptException:
> sun.org.mozilla.javascript.internal.WrappedException: Wrapped
> java.lang.NullPointerException
>
> When I comment out the problematic line (var nObjects = rm.getCount();) I
> get the following Roi Manager type for the rm: (getInstance returned this)
>
> The returned rm is:
> ij.plugin.frame.RoiManager[frame61,884,327,240x330,invalid,layout=java.awt.BorderLayout,title=ROI
> Manager,resizable,normal]
>
> How would I count the number of ROIs in the Roi manager? And how can I use
> the RoiManager class methods?
>
> Thanks,
> Avital

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html