How do imageJ1 plugins process a recorded command

Hi all,
I managed to write an ImageJ1 plugin and it works as expected, I even get a nicely formatted command in the macro-recorder.
However, if I try to run the plugin using the macro-recorded command, it does not work, which is not very surprising because the code does not consider this option.

The problem is that I actually don’t know how to adapt the code to get and process the recorded command. I though it is passed to the run(arg) method via the arg parameters, but IJ.log(arg) was actually empty when the plugin is called with the macro-recorded command.

This is the structure I used for the plugin, which I had seen in some example.

public class My_Plugin implements PlugIn {
    private	String someInput;

	public void run(String arg) {
         IJ.log(arg); // always empty
		 if (!showDialog()) return; // Dialog cancelled
		 IJ.log(this.someInput);

	}
	
	public boolean showDialog(){
		dialog = new GenericDialog("Test");
		dialog.addStringField("my input", "");
		dialog.showDialog();
		if (dialog.wasCancelled()) return false;
		
		// read dialog input and store in plugin variables
		this.someInput = dialog.getNextString();
		return true;
	}
}

Hey Laurent @LThomas ,

from looking at it I’d say this should work. I assume the recorder records something like this?

run("menu name", "my=text");

And “text” should end up in this.someInput.

If you want to pass something to the arg parameter, you can only do this via plugins.config, e.g. as shown here by the end of the line:

Does this help?

Cheers,
Robert

2 Likes

Hi @haesleinhuepf ,
Thanks for the prompt reply and the clarification about arg, indeed the test plugin above works (I should have tested it myself :stuck_out_tongue: ).
So I guess I am messing something up in my actual plugin. I use a custom subclass of GenericDialog and I implemented some functions to read the GUI state for the elements that are always there.
It might have broken the macro-recording logic though… I will dig up…

1 Like

Hi Laurent,
when a macro is running, the options are filled into the fields of the GenericDialog (they are not in the arg of the run method). If you extend the GenericDialog, your added input fields won’t be known to ImageJ, so it cannot fill in values there.
You can get the options String with
String options = Macro.getOptions();
and decode it yourself.
For recording, I am not sure whether or how you can add your options. Best have a look at the GenericDialog source, this should tell you more.
–Michael

3 Likes