Hello everyone,
I am running a plugin that I have coded (using the GenericDialog class, so the parameters can be passed from a macro) and I am encountering a problem in the following line: run("Average Frames", "first=1 last=&frames"); This plugin just does the averaging of an image using the first and last frames passed as arguments. The "frames" variable is set, I have checked. If I run this line in its current form, I get the following error: ImageJ 1.48a; Java 1.6.0_38-ea [64-bit]; Windows 7 6.1; 521MB of 4096MB (12%) java.lang.NumberFormatException: For input string: "frames" ... So, looks like the argument has been passed as a string and not as the value content (the plugin, of course, expects a number). If instead I use run("Average Frames", "first=1 last=" + frames); Everything works like a charm. I understod that the "&variable_name" shortcut can be used inside the run() method and the variable_name contents would be passed as the tool parameter. Am I missing something here? Best, José. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Aug 27, 2013, at 6:45 AM, José María Mateos wrote:
> Hello everyone, > > I am running a plugin that I have coded (using the GenericDialog > class, so the parameters can be passed from a macro) and I am > encountering a problem in the following line: > > run("Average Frames", "first=1 last=&frames"); I am unable to duplicate this problem using this test plugin: import ij.*; import ij.gui.*; import ij.plugin.*; public class Average_Frames implements PlugIn { int first=1, last=10; public void run(String arg) { GenericDialog gd = new GenericDialog("Test Dialog"); gd.addNumericField("First frame: ", first, 0); gd.addNumericField("Last frame: ", last, 0); gd.showDialog(); if (gd.wasCanceled()) return; first = (int)gd.getNextNumber(); last = (int)gd.getNextNumber(); IJ.log(first+" "+last); } } When I run this macro frames = 33; run("Average Frames", "first=1 last=&frames"); I get 1 33 as output. -wayne > This plugin just does the averaging of an image using the first and > last frames passed as arguments. The "frames" variable is set, I have > checked. If I run this line in its current form, I get the following > error: > > ImageJ 1.48a; Java 1.6.0_38-ea [64-bit]; Windows 7 6.1; 521MB of 4096MB (12%) > java.lang.NumberFormatException: For input string: "frames" > ... > > So, looks like the argument has been passed as a string and not as the > value content (the plugin, of course, expects a number). If instead I > use > > run("Average Frames", "first=1 last=" + frames); > > Everything works like a charm. I understod that the "&variable_name" > shortcut can be used inside the run() method and the variable_name > contents would be passed as the tool parameter. Am I missing something > here? > > Best, > > José. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
2013/8/27 Rasband, Wayne (NIH/NIMH) [E] <[hidden email]>:
> I am unable to duplicate this problem using this test plugin: > > import ij.*; > import ij.gui.*; > import ij.plugin.*; > > public class Average_Frames implements PlugIn { > int first=1, last=10; > > public void run(String arg) { > GenericDialog gd = new GenericDialog("Test Dialog"); > gd.addNumericField("First frame: ", first, 0); > gd.addNumericField("Last frame: ", last, 0); Thanks for your answer, Wayne. I think I've found where we are diverging. My plugin (BTW, code at https://github.com/HGGM-LIM/limtools/blob/master/src/main/java/limtools/Average_Frames.java) does not build its GUI with gd.addNumericField but with gd.addChoice (so I can limit the range of values the user can provide). Might it be a bug in the variable conversion when using the addChoice method? Best, José. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
José,
when using a list for a drop down menu, the items are strings, at least in the IJ-macro language. HTH Herbie _________________________________________ On 27.08.13 17:42, José María Mateos wrote: > 2013/8/27 Rasband, Wayne (NIH/NIMH) [E] <[hidden email]>: >> I am unable to duplicate this problem using this test plugin: >> >> import ij.*; >> import ij.gui.*; >> import ij.plugin.*; >> >> public class Average_Frames implements PlugIn { >> int first=1, last=10; >> >> public void run(String arg) { >> GenericDialog gd = new GenericDialog("Test Dialog"); >> gd.addNumericField("First frame: ", first, 0); >> gd.addNumericField("Last frame: ", last, 0); > > Thanks for your answer, Wayne. I think I've found where we are > diverging. My plugin (BTW, code at > https://github.com/HGGM-LIM/limtools/blob/master/src/main/java/limtools/Average_Frames.java) > does not build its GUI with gd.addNumericField but with gd.addChoice > (so I can limit the range of values the user can provide). Might it be > a bug in the variable conversion when using the addChoice method? > > Best, > > José. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by José María Mateos
On Aug 27, 2013, at 11:42 AM, José María Mateos wrote:
> 2013/8/27 Rasband, Wayne (NIH/NIMH) [E] <[hidden email]>: >> I am unable to duplicate this problem using this test plugin: >> >> import ij.*; >> import ij.gui.*; >> import ij.plugin.*; >> >> public class Average_Frames implements PlugIn { >> int first=1, last=10; >> >> public void run(String arg) { >> GenericDialog gd = new GenericDialog("Test Dialog"); >> gd.addNumericField("First frame: ", first, 0); >> gd.addNumericField("Last frame: ", last, 0); > > Thanks for your answer, Wayne. I think I've found where we are > diverging. My plugin (BTW, code at > https://github.com/HGGM-LIM/limtools/blob/master/src/main/java/limtools/Average_Frames.java) > does not build its GUI with gd.addNumericField but with gd.addChoice > (so I can limit the range of values the user can provide). Might it be > a bug in the variable conversion when using the addChoice method? The GenericDialog.getNextChoice() method expects a string so you can work around the problem by calling the plugin using a macro something like frames = "5"; run("Average Frames", "first=1 last=&frames"); Or upgrade to the ImageJ 1.48c daily build, which converts numeric variables to strings, and you can use frames = 5; run("Average Frames", "first=1 last=&frames"); -wayne -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
2013/8/28 Rasband, Wayne (NIH/NIMH) [E] <[hidden email]>:
> The GenericDialog.getNextChoice() method expects a string so you can work around the problem by calling the plugin using a macro something like > > frames = "5"; > run("Average Frames", "first=1 last=&frames"); Aaaaaaah, OK. Didn't think of that. My bad. Thanks a lot for the quick answer to everyone. Best, José. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |