Hi,
I am curious about this: Below is the SineCosineTable2.txt macro from the IJ site, why does one have to surround the title in "[ ]" to create the table and print to it, but use the same string without "[ ]" to test whether it is open? -------8<-------- requires("1.38m"); title1 = "Sine/Cosine Table"; title2 = "["+title1+"]"; f = title2; if (isOpen(title1)) print(f, "\\Clear"); else run("New... ", "name="+title2+" type=Table width=250 height=600"); print(f, "\\Headings:n\tSine\tCosine"); for (n=0; n<=2*PI; n += 0.1) print(f, n + "\t" + sin(n) + "\t" + cos(n)); -------8<-------- Thanks, Gabriel |
Hi Gabriel,
The name of the window is "Sine/Cosine Table" without the brackets. But when passing a plugin argument string, you must place brackets around argument values with spaces -- otherwise it would be interpreted (in this case) as "name=Sine/Cosine" with "Table" as an enabled boolean parameter. For print, according to the macro language documentation, multiple arguments with commas are just concatenated with a space between each, meaning you would have the same problem of ambiguous window titling if brackets were not used. None of this is an issue for window titles with no spaces. -Curtis On 5/17/07, Gabriel Landini <[hidden email]> wrote: > Hi, > I am curious about this: > Below is the SineCosineTable2.txt macro from the IJ site, why does one have to > surround the title in "[ ]" to create the table and print to it, but use the > same string without "[ ]" to test whether it is open? > > -------8<-------- > requires("1.38m"); > title1 = "Sine/Cosine Table"; > title2 = "["+title1+"]"; > f = title2; > if (isOpen(title1)) > print(f, "\\Clear"); > else > run("New... ", "name="+title2+" type=Table width=250 height=600"); > print(f, "\\Headings:n\tSine\tCosine"); > for (n=0; n<=2*PI; n += 0.1) > print(f, n + "\t" + sin(n) + "\t" + cos(n)); > -------8<-------- > > Thanks, > > Gabriel > |
On Thursday 17 May 2007 14:47:28 Curtis Rueden wrote:
> None of this is an > issue for window titles with no spaces. I agree in theory, but not in practice :-) Not sure if this is a bug, then: This does not work in linux (it prints to the Log window instead): //====================== f1 = "Test"; f2 = "["+f1+"]"; // --- to a table window if(!isOpen(f1)){ run("New... ", "name="+f1+" type=Table width=300 height=400"); print(f1, "\\Headings:Filed1\tField2\tField3"); } x=1; y=2; z=3; print(f1,x+"\t"+y+"\t"+z); //====================== But this does work (i.e. it prints to the Test table): The difference is the [ ] in the table creation and the print statements. They are both strings without spaces. //====================== f1 = "Test"; f2 = "["+f1+"]"; // --- to a table window if(!isOpen(f1)){ run("New... ", "name="+f2+" type=Table width=300 height=400"); print(f2, "\\Headings:Filed1\tField2\tField3"); } x=1; y=2; z=3; print(f2,x+"\t"+y+"\t"+z); //====================== Cheers, Gabriel |
Hi Gabriel,
Ah, I should have read the macro documentation more thoroughly. From the web site: "Starting with ImageJ 1.38m, the second argument to print(arg1, arg2) is appended to a text window or table if the first argument is a window title in brackets." So the situation with print is a special case. If the first argument is something in brackets, it is interpreted as a file. Otherwise, it is merely concatenated. Note that your working macro still works if you change the f2 to f1 in the "run" command (because "Test" contains no spaces). -Curtis On 5/17/07, Gabriel Landini <[hidden email]> wrote: > On Thursday 17 May 2007 14:47:28 Curtis Rueden wrote: > > None of this is an > > issue for window titles with no spaces. > > I agree in theory, but not in practice :-) > Not sure if this is a bug, then: > > This does not work in linux (it prints to the Log window instead): > > //====================== > f1 = "Test"; > f2 = "["+f1+"]"; > > // --- to a table window > if(!isOpen(f1)){ > run("New... ", "name="+f1+" type=Table width=300 height=400"); > print(f1, "\\Headings:Filed1\tField2\tField3"); > } > x=1; > y=2; > z=3; > print(f1,x+"\t"+y+"\t"+z); > //====================== > > But this does work (i.e. it prints to the Test table): > The difference is the [ ] in the table creation and the print statements. They > are both strings without spaces. > > //====================== > f1 = "Test"; > f2 = "["+f1+"]"; > > // --- to a table window > if(!isOpen(f1)){ > run("New... ", "name="+f2+" type=Table width=300 height=400"); > print(f2, "\\Headings:Filed1\tField2\tField3"); > } > > x=1; > y=2; > z=3; > > print(f2,x+"\t"+y+"\t"+z); > //====================== > > Cheers, > > Gabriel > |
On Thursday 17 May 2007 17:00:38 Curtis Rueden wrote:
> Hi Gabriel, > > Ah, I should have read the macro documentation more thoroughly. From > the web site: > > "Starting with ImageJ 1.38m, the second argument to print(arg1, arg2) > is appended to a text window or table if the first argument is a > window title in brackets." > > So the situation with print is a special case. If the first argument > is something in brackets, it is interpreted as a file. Otherwise, it > is merely concatenated. > Note that your working macro still works if you change the f2 to f1 in > the "run" command (because "Test" contains no spaces). I was not sure of why of this. It seems a bit convoluted, but perhaps there is no other way of indicating what the argument means? Thanks again, Gabriel |
Free forum by Nabble | Edit this page |