Question about Tables

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about Tables

Craig Uhrich
I love the new Table.* macro commands introduced in 1.52a .

I don't see a way for a macro to determine if a certain Table already exists.   The obvious solution is to have a Table.exists() function, but that doesn't seem to be available.   Is there a common workaround trick?

Thanks,
             -Craig


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Question about Tables

Michael Schmid-3
On 14.12.18 20:14, Craig Uhrich wrote:

 > I don't see a way for a macro to determine if a certain Table already
exists.
 > The obvious solution is to have a Table.exists() function, but that
doesn't seem to be available.
 > Is there a common workaround trick?


Hi Craig,

there is a workaround, but one needs to get the table into the foreground:

title="My Table";
type="";
if (isOpen(title)) {
   selectWindow(title);
   type=getInfo("window.type");
}
if (type=="ResultsTable")
   showMessage("Yes, we have a table named "+title);

If you are sure that nothing but a table can have the given title, of
course you can simply use isOpen(title).


When adding a new macro function (if there is not better alternative
already that I am not aware of), I would prefer a function that also
works for other Window types.
E.g.
   getWindowType(windowTitle)
(which would return a blank String or, e.g. "ERROR" if there is no such
window), or
   isOpen(windowTitle, windowType)
(which would check whether the window is open AND has the specified type) or
   getList("window.titles", windowType)
which would only return the windows of the given type, and we would need
an additional
   Array.contains(array, value)
or
   Array.firstIndexOf(array, value)
macro function (the latter would return -1 if there is no such array
element)


Michael

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Question about Tables

Craig Uhrich
In reply to this post by Craig Uhrich
Michael,
Thanks for your suggestion.   But I don't see how I can get the table to the foreground if the table doesn't exist.

I cobbled together a workaround for my initial question using the existing getList("window.titles") function.

// Create "TDI_Prec" table if it doesn't already exist
t_name = "TDI_Prec";
table_exists = false;
wins = getList("window.titles");
for (i=0; i<wins.length; i++) if (wins[i] == t_name) table_exists = true;
if (table_exists) {
  row = Table.size(t_name);  
  } else {
  Table.create(t_name);
  row = 0;
  }

It may not be elegant, but it creates the Table window if none exists, and allows me to append if the Table is already there.

                   -Craig

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Question about Tables

Michael Schmid-3
Hi Craig,

what I wanted to say: You have to live with it that my macro takes the
table into the foreground (if it exists).
E.g., if you have previously had something else in the foreground, and
you want to keep it in the foreground, you have to put it into the
foreground again after running my macro.

   title="TDI_Prec";
   type="";
   if (isOpen(title)) {
     selectWindow(title);    // put window "TDI_Prec" to foreground
     type=getInfo("window.type");  //get type of that window
   }
   if (type=="ResultsTable") // check whether it is a table
     showMessage("Yes, we have a table named "+title);

Your macro should also work well (as long as "TDI_Prec" is a table, not
something else). It is essentially equivalent to

   table_exists = isOpen("TDI_Prec");


Michael
________________________________________________________________
On 17.12.18 18:18, Craig Uhrich wrote:

> Michael,
> Thanks for your suggestion.   But I don't see how I can get the table to the foreground if the table doesn't exist.
>
> I cobbled together a workaround for my initial question using the existing getList("window.titles") function.
>
> // Create "TDI_Prec" table if it doesn't already exist
> t_name = "TDI_Prec";
> table_exists = false;
> wins = getList("window.titles");
> for (i=0; i<wins.length; i++) if (wins[i] == t_name) table_exists = true;
> if (table_exists) {
>    row = Table.size(t_name);
>    } else {
>    Table.create(t_name);
>    row = 0;
>    }
>
> It may not be elegant, but it creates the Table window if none exists, and allows me to append if the Table is already there.
>
>                     -Craig
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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