Hi,
I am trying to run an ImageJ macro in a java plugin using IJ.runMacro. I would like to understand how to pass the macro a string argument. The following code doesn't work: String simpleMacro = "String greeting = getArgument();"+ "print(greeting);"; IJ.runMacro(simpleMacro,"hi"); What am I doing wrong? How can I pass the macro the string argument "hi" and get the macro to print it? Thank you, Avital -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Nov 13, 2014, at 6:57 AM, Avital Steinberg <[hidden email]> wrote:
> Hi, > I am trying to run an ImageJ macro in a java plugin using IJ.runMacro. I > would like to understand how to pass the macro a string argument. The > following code doesn't work: > > String simpleMacro = > "String greeting = getArgument();"+ > "print(greeting);"; > > IJ.runMacro(simpleMacro,"hi"); > > What am I doing wrong? How can I pass the macro the string argument "hi" > and get the macro to print it? > Hi, I think that your simpleMacro needs to point to the file where the macro is stored. That said, it is an interesting idea to construct macros on the fly to run from a script/plugin. Anyway, the details can be found here... http://rsb.info.nih.gov/ij/developer/api/ij/IJ.html#runMacro(java.lang.String,%20java.lang.String) Cheers, Ben > Thank you, > Avital > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thank you - I succeeded in passing an argument to the macro like this:
String simpleMacro = //"String XdotY=getArgument();" + "greeting = getArgument();"+ "print(greeting);"; IJ.runMacro(simpleMacro,"hi"); But I still have a problem - I am unable to use a return statement. For example, this doesn't work: String simpleMacro2 = //"String XdotY=getArgument();" + "greeting = getArgument();"+ "return(greeting);"; String hello = IJ.runMacro(simpleMacro2,"hi"); IJ.log(hello); I don't get any output - I get an error message saying: "invalid context". Thanks, Avital On Thu, Nov 13, 2014 at 4:09 PM, Ben Tupper <[hidden email]> wrote: > On Nov 13, 2014, at 6:57 AM, Avital Steinberg <[hidden email]> > wrote: > > > Hi, > > I am trying to run an ImageJ macro in a java plugin using IJ.runMacro. I > > would like to understand how to pass the macro a string argument. The > > following code doesn't work: > > > > String simpleMacro = > > "String greeting = getArgument();"+ > > "print(greeting);"; > > > > IJ.runMacro(simpleMacro,"hi"); > > > > What am I doing wrong? How can I pass the macro the string argument "hi" > > and get the macro to print it? > > > > Hi, > > I think that your simpleMacro needs to point to the file where the macro > is stored. That said, it is an interesting idea to construct macros on the > fly to run from a script/plugin. Anyway, the details can be found here... > > > http://rsb.info.nih.gov/ij/developer/api/ij/IJ.html#runMacro(java.lang.String,%20java.lang.String) > > > Cheers, > Ben > > > > Thank you, > > Avital > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Actually, I also found the way to return the string:
String simpleMacro2 = "greeting = getArgument();"+ "return greeting;"; String hello = IJ.runMacro(simpleMacro2,"hi"); IJ.log(hello); So the problem is solved - thanks, Avital On Thu, Nov 13, 2014 at 4:47 PM, Avital Steinberg <[hidden email] > wrote: > Thank you - I succeeded in passing an argument to the macro like this: > > String simpleMacro = > //"String XdotY=getArgument();" + > "greeting = getArgument();"+ > "print(greeting);"; > > IJ.runMacro(simpleMacro,"hi"); > > But I still have a problem - I am unable to use a return statement. For > example, this doesn't work: > > String simpleMacro2 = > //"String XdotY=getArgument();" + > "greeting = getArgument();"+ > "return(greeting);"; > > String hello = IJ.runMacro(simpleMacro2,"hi"); > IJ.log(hello); > > I don't get any output - I get an error message saying: "invalid context". > > Thanks, > Avital > > > > On Thu, Nov 13, 2014 at 4:09 PM, Ben Tupper <[hidden email]> wrote: > >> On Nov 13, 2014, at 6:57 AM, Avital Steinberg <[hidden email]> >> wrote: >> >> > Hi, >> > I am trying to run an ImageJ macro in a java plugin using IJ.runMacro. I >> > would like to understand how to pass the macro a string argument. The >> > following code doesn't work: >> > >> > String simpleMacro = >> > "String greeting = getArgument();"+ >> > "print(greeting);"; >> > >> > IJ.runMacro(simpleMacro,"hi"); >> > >> > What am I doing wrong? How can I pass the macro the string argument "hi" >> > and get the macro to print it? >> > >> >> Hi, >> >> I think that your simpleMacro needs to point to the file where the macro >> is stored. That said, it is an interesting idea to construct macros on the >> fly to run from a script/plugin. Anyway, the details can be found here... >> >> >> http://rsb.info.nih.gov/ij/developer/api/ij/IJ.html#runMacro(java.lang.String,%20java.lang.String) >> >> >> Cheers, >> Ben >> >> >> > Thank you, >> > Avital >> > >> > -- >> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |