saving multiple text windows

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

saving multiple text windows

Richard Mort-2
I have a whole bunch of windows open and I'd like to just save the ones with "Raw" in the title and append the names to 1_Raw.xls, 2_Raw.xls etc etc. I think the following macro code should work:

window = 0;
window_ID = 0;
list = getList("window.titles");
for (b=1; b<(list.length); b++) {
window = substring(list [b], 0, 3);
if (window=="Raw") {
     window_ID++;
     selectWindow(list [b]);
         saveAs("Measurements", window_ID+"_Raw.xls");}
     else {}

It finds the windows and saves the correct number of files but when I open them they are all the same. On further investigation when I try and manually save each window and then I go to open them they are all the same too! So I don't think the problem is my code as in-elegant as it may be. I am trying to save the output from the WrMTrck plugin (http://www.phage.dk/plugins/wrmtrck.html).

Using Fiji with ImageJ version 1.46k

--
Dr Richard Mort
MRC Human Genetics Unit
MRC IGMM
University of Edinburgh
Western General Hospital
Crewe Road
Edinburgh.
EH4 2XU, UK

Tel: +44 (0)131 332 2471
Fax: +44 (0)131 467 8456


The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
Reply | Threaded
Open this post in threaded view
|

Re: saving multiple text windows

dscho
Hi Richard,

On Tue, 17 Apr 2012, Richard Mort wrote:

> I have a whole bunch of windows open and I'd like to just save the ones with
> "Raw" in the title and append the names to 1_Raw.xls, 2_Raw.xls etc etc. I
> think the following macro code should work:
>
> window = 0;
> window_ID = 0;
> list = getList("window.titles");
> for (b=1; b<(list.length); b++) {
> window = substring(list [b], 0, 3);
> if (window=="Raw") {
>     window_ID++;
>     selectWindow(list [b]);
>         saveAs("Measurements", window_ID+"_Raw.xls");}

As far as I can tell, IJ1 can track only one instance of a Results window.

>     else {}
>
> It finds the windows and saves the correct number of files but when I open
> them they are all the same. On further investigation when I try and manually
> save each window and then I go to open them they are all the same too! So I
> don't think the problem is my code as in-elegant as it may be. I am trying to
> save the output from the WrMTrck plugin
> (http://www.phage.dk/plugins/wrmtrck.html).
>
> Using Fiji with ImageJ version 1.46k

Since you are using Fiji, Beanshell scripting is available. So something
like this might work (File>New>Script, then Language>Beanshell, paste and
Run>Run):

-- snipsnap --
counter = 1;
for (java.awt.Frame frame : WindowManager.getNonImageWindows()) {
        if (!(frame instanceof TextWindow))
                continue;
        textPanel = frame.getTextPanel();
        if (textPanel == null)
                continue;
        resultsTable = textPanel.getResultsTable();
        if (resultsTable == null)
                continue;
        resultsTable.saveAs(counter + "_Raw.xls");
        counter++;
}