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:
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html