Hi,
I'd like to write a macro that manipulates a Results table that is the output of a plugin, so the Results table is pre-existing to the macro launch. I could'nt find macro functions for the following : - get the title of the currently active Results Table - get the number and headers of the columns, so that I can then use getResult("Column", index) to access the values. One workaround would be to dump the results table in the clipboard (string.copyResults()) and then get the clipboard as a string (string.Paste), and then manipulate the string, but I'm working with large tables so I'm reluctant to add back-and-forth copies. Plus it doesn't give me the table title. Thanks for your help, Christophe |
On Feb 28, 2012, at 8:49 AM, Christophe Leterrier wrote:
> Hi, > > I'd like to write a macro that manipulates a Results table that is the > output of a plugin, so the Results table is pre-existing to the macro > launch. > > I could'nt find macro functions for the following : > - get the title of the currently active Results Table The active Results window always has the title "Results". > - get the number and headers of the columns, so that I can then use > getResult("Column", index) to access the values. In the ImageJ 1.46h daily build, you can use the String.getResultsHeadings() macro function to get the headers. Here is an example that prints the contents of the Results window: headings = split(String.getResultsHeadings); for (row=0; row<nResults; row++) { line = ""; for (col=0; col<lengthOf(headings); col++) line = line + getResult(headings[col],row) + " "; print(line); } -wayne > One workaround would be to dump the results table in the clipboard > (string.copyResults()) and then get the clipboard as a string > (string.Paste), and then manipulate the string, but I'm working with large > tables so I'm reluctant to add back-and-forth copies. Plus it doesn't give > me the table title. > > Thanks for your help, > > Christophe |
Hi Wayne,
On Tue, Feb 28, 2012 at 23:09, Rasband, Wayne (NIH/NIMH) [E] < [hidden email]> wrote: > On Feb 28, 2012, at 8:49 AM, Christophe Leterrier wrote: > > > Hi, > > > > I'd like to write a macro that manipulates a Results table that is the > > output of a plugin, so the Results table is pre-existing to the macro > > launch. > > > > I could'nt find macro functions for the following : > > - get the title of the currently active Results Table > > The active Results window always has the title "Results". > The plugin I use outputs a table that is called "Localized Molecules". If I execute commands such as getResult() after the plugin has finished and the table is open (it is the only existing results table), this table is treated as the primary Results table (meaning that I can get the values inside it using getResult()), although it is not named "Results". Is that expected? Another related question, how can I get a list of all open results table and their title in case I made and renamed several ones? > > > - get the number and headers of the columns, so that I can then use > > getResult("Column", index) to access the values. > > In the ImageJ 1.46h daily build, you can use the > String.getResultsHeadings() macro function to get the headers. Here is an > example that prints the contents of the Results window: > > headings = split(String.getResultsHeadings); > for (row=0; row<nResults; row++) { > line = ""; > for (col=0; col<lengthOf(headings); col++) > line = line + getResult(headings[col],row) + " "; > print(line); > } Nice, thanks ! Christophe -wayne > > > One workaround would be to dump the results table in the clipboard > > (string.copyResults()) and then get the clipboard as a string > > (string.Paste), and then manipulate the string, but I'm working with > large > > tables so I'm reluctant to add back-and-forth copies. Plus it doesn't > give > > me the table title. > > > > Thanks for your help, > > > > Christophe > |
On Tuesday 28 Feb 2012 23:27:20 Christophe Leterrier wrote:
> The plugin I use outputs a table that is called "Localized Molecules". If I > execute commands such as getResult() after the plugin has finished and the > table is open (it is the only existing results table), this table is > treated as the primary Results table (meaning that I can get the values > inside it using getResult()), although it is not named "Results". Is that > expected? As I understand there is only 1 Results table active at a time. If you rename it and run another plugin that outputs to "Results", IJ will open a new window and table which will be "the" Results table. If you close it, the variable nResults(whcih gives you the number of rows in the table) goes to 0, so I can't see how one could retrieve the data from the first one with getResult(). Under linux, as soon as you rename the Results table with e.g. IJ.renameResults("test"); the nResults variable goes to 0. Do you see that? You said that you can access the data in the renamed table... but the pointer says there is no Results data. > Another related question, how can I get a list of all open results table > and their title in case I made and renamed several ones? Maybe getList("window.titles") would help? (these are non-image windows) but I wonder whether one can retrieve from the other renamed tables. Of course you can export and import different data to the Results table to use data collected at different times, but I am sure you are aware of this. Cheers Gabriel |
On Wed, Feb 29, 2012 at 13:24, Gabriel Landini <[hidden email]> wrote:
> > On Tuesday 28 Feb 2012 23:27:20 Christophe Leterrier wrote: > > The plugin I use outputs a table that is called "Localized Molecules". If I > > execute commands such as getResult() after the plugin has finished and the > > table is open (it is the only existing results table), this table is > > treated as the primary Results table (meaning that I can get the values > > inside it using getResult()), although it is not named "Results". Is that > > expected? > > As I understand there is only 1 Results table active at a time. If you rename > it and run another plugin that outputs to "Results", IJ will open a new window > and table which will be "the" Results table. If you close it, the variable > nResults(whcih gives you the number of rows in the table) goes to 0, so I > can't see how one could retrieve the data from the first one with getResult(). The plugin outputs a Results Table with the title "Localization Results" using: results.show("Localization Results"); and after completion of the plugin, this table is accessible via macro functions such as nResults() and getResult(). Moreover, you can do IJ.renameResults("New"); print(nResults); the table will be renamed, and nResults will still point to the table. I guess this is not consistent with what happens when using a Results Table through GUI point n clicks (see below). > Under linux, as soon as you rename the Results table with e.g. > IJ.renameResults("test"); > the nResults variable goes to 0. Do you see that? You said that you can access > the data in the renamed table... but the pointer says there is no Results > data. > You're right, in the case the table was not the output of a plugin via rt.show("Title") (see above). Consider the following macro : run("AuPbSn 40 (56K)"); setAutoThreshold("Default dark"); setThreshold(126, 255); run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing display"); print(nResults); IJ.renameResults("New"); print(nResults); The first nResults gives you 41, the second one 0. So I guess there is a discrepency between this and the case of a table generated by a plugin after plugin completion. > > Another related question, how can I get a list of all open results table > > and their title in case I made and renamed several ones? > > Maybe getList("window.titles") would help? (these are non-image windows) but I > wonder whether one can retrieve from the other renamed tables. > I found this message from Wayne on the list from when the Results Table renaming was implemented, explaining how to retrieve several Results Tables via macro: http://imagej.1557.n6.nabble.com/Two-result-tables-possible-td3687562.html You can create multiple result tables in the 1.44c4 daily build by using the new "Rename" command, available in the File menu of Results windows. [...] Macro functions like getResults() only work with the primary results table so you have to rename the table you want to access to "Results". I have included an example. Plugins and scripts can get a reference to the underlining ResultsTable object and use the rt.getValue() method. > > Of course you can export and import different data to the Results table to use > data collected at different times, but I am sure you are aware of this. > > Cheers > Gabriel Cheers, Christophe |
Free forum by Nabble | Edit this page |