-1

I am trying to pass an argument from an ImageJ plugin to an imageJ macro. Basically, I call the macro from within my ImageJ Java plugin to open a stack of images and would like to be able to pass an integer value to the plugin to be able to append it to the end of a file path.

Right now I am able to open a stack of images, perform whatever operations I need to do to the active image inside the plugin, and then close the image stack so I can open the next stack of images.

This is the basic format of what I am doing in the Java Plugin:

(general import stuff)

import ij.plugin.Macro_Runner;

Macro_Runner test_runner = new Macro_Runner();
test_runner.run("OpenFrameSequence.ijm");
// pixel analysis
test_runner.run("closeMacro.ijm");**

Here is the Macro OpenFrameSequence.ijm:

var x = 0;
x = getNumber("Bias Frame Sequence Length:", x); 
run("Image Sequence...", "open=[C:\\Documents and Settings\\Developer\\Desktop\\PLPT_IMAGEJ_PICS\\BiasFrameSequence\\1.jpg] number=x sort use");

Here is the Macro closeMacro.imj

close();

The fourth line in the plugin section above is what I am having trouble with, there is another function that I can call runMacro(); which is defined here:

http://rsbweb.nih.gov/ij/developer/api/ij/plugin/Macro_Runner.html

So what I want to do is this:

int i = 1;

test_runner.runMacro("OpenFrameSequence.ijm", i);

And then, in the macro, take the value of i and use it as a variable. The runMacro() function doesn't seem to be working (i've also tried to send a String in place of the int i).

Any help would be appreciated.

Jan Eglinger
  • 3,995
  • 1
  • 25
  • 51
user3716193
  • 476
  • 5
  • 21

1 Answers1

0

In the javadoc of Macro_Runner#runMacro(String macro, String arg), it says:

Runs the specified macro on the current thread. Macros can retrieve the optional string argument by calling the getArgument() macro function. Returns the string value returned by the macro, null if the macro does not return a value, or "[aborted]" if the macro was aborted due to an error.

so the following Javascript (and the equivalent Java) works as expected:

importClass(Packages.ij.plugin.Macro_Runner);

var i = 42;
mr = new Macro_Runner();
mr.runMacro("print(getArgument());", i);

If you want to run a macro file instead of raw macro code, you should use Macro_Runner#runMacroFile:

test_runner.runMacroFile("OpenFrameSequence.ijm", i);
Jan Eglinger
  • 3,995
  • 1
  • 25
  • 51