Posted by
Rasband, Wayne (NIH/NIMH) [E] on
Aug 27, 2013; 3:33pm
URL: http://imagej.273.s1.nabble.com/Problem-with-variable-in-run-macro-statement-tp5004565p5004572.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