Re: combine function of the ROI manager
Posted by Rasband, Wayne (NIH/NIMH) [E] on Aug 06, 2010; 9:47pm
URL: http://imagej.273.s1.nabble.com/combine-function-of-the-ROI-manager-tp3685239p3685242.html
On Aug 6, 2010, at 1:13 PM, Sebastien Tosi wrote:
> Thank you Wayne, this works fine. Now I have to find out how to call
> javascript from a macro and pass arguments to the script (here basically the
> 2 indexes of the ROIs to be merged)... what is the best way to do this?
A macro can call JavaScript using the eval() function. Here is an example:
index1 = 1;
index2 = 3;
script =
"index1="+index1+";\n" +
"index1="+index2+";\n" +
"manager = RoiManager.getInstance();\n" +
"if (manager==null)\n" +
" IJ.error(\"ROI Manager is not open\");\n" +
"rois = manager.getRoisAsArray();\n" +
"roi1 = new ShapeRoi(rois[1]);\n" +
"roi2 = new ShapeRoi(rois[3]);\n" +
"combined = roi1.or(roi2);\n" +
"manager.addRoi(combined);\n";
eval("script", script);
-wayne