Login  Register

Re: Close all but active window

Posted by Michael Schmid on Nov 18, 2016; 5:41pm
URL: http://imagej.273.s1.nabble.com/Close-all-but-active-window-tp5014024p5017600.html

Hi Haleh,

sorry, there was a typo in the check for 'Stack1.tif' and 'Stack2.tif'
(I wrote 'Stack1.tif' twice), otherwise it works for me.
Here is a full JavaScript example:


imp=IJ.createImage("Stack1.tif", "8-bit white", 128, 128, 2);
imp.show();
imp=IJ.createImage("closeMe1", "8-bit white", 128, 128, 2);
imp.show();
imp=IJ.createImage("closeMe2", "8-bit white", 128, 128, 1);
imp.show();
imp=IJ.createImage("Stack2.tif", "8-bit white", 256, 256, 3);
imp.show();
IJ.wait(1000); //allows the user to see what we have
closeAllButStack12();

// Closes all visible images except for 'Stack1.tif' and 'Stack2.tif'
//
function closeAllButStack12() {
   allIDs = WindowManager.getIDList();
   if (allIDs==null) return;  // if null, there are no open images
   for (i = 0; i<allIDs.length; i++) {
     imp = WindowManager.getImage(allIDs[i]);
     title = imp.getTitle();
     if (title != "Stack1.tif" && title != "Stack2.tif") {
       win = imp.getWindow();
       if (win != null) {
         imp.changes = false;
         win.close();
       }
     }
   }
}


Michael
________________________________________________________________
On 2016-11-18 12:03, Haleh wrote:

> Hi,
>
> Thank you Micheal.
>
> I tried your commands. Unfortunately I got an error: (There are no images
> open). As my images are visible it might be problem in getting ID of desired
> images. Don't know !!!
>
> Haleh
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Close-all-but-active-window-tp5014024p5017594.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>

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