Close all AnalyzeParticle windows from Macro

Dear all,

how can I reliable close all windows opened from a AnalyzeParticles call from an ImageJ macro?

Sorry to bother, but I didn’t find a sound way to do this.

Best wishes,
Stephan

You just need to use close(windowTitle).
For the Summary table for example: close("Summary");

If you open the ROI manager then it is recommended to reset the ROI manager window instead of closing it: roiManager("reset")
Avoids error messages in case the ROI manager window has not been opened.

1 Like

So the lines of code I’l have to add:

close("Results");
roiManager("reset")
close("Summary");

Thank you!

Somebody sent me an email and said I can use close("*") too.

If these are all the windows that are open yes. The close("*") will only close all image windows as far as I know, not result tables, tables or the ROI Manager.

The only caveat is that if you have no objects in your image than the display results option will throw an error message. I usually add to the manager and check if there are ROIs created. With an if else statement you can skip the measurement if there are not ROIs at all.

In any case you need to account for situations where some windows are not created. For example the ROI manager and the Results window are windows that do not get opened if there are no objects or measurements. So I would usually check if windows such as the Results window are open before closing them with the isOpen(id) function and an if/else statement.

EDIT: for the Result window you can also use run("Clear Results") same as with the roiManager("reset") it avoids an error message if the Results window is not open.

1 Like