質問

Hello I am trying to pass arguments to my ImageJ PlugIn. However it seems no matter what I pass, argument string will be considered as empty by the program. I couldn't find any documentation on the internet about THAT issue.

My Java plugIn looks like this, and compiles fine.

import ij.plugin.PlugIn;

public class Test implements PlugIn {
    public void run(String args) {

        IJ.log("Starting plugin Test");
        IJ.log("args: ." + args + ".");

    }
 }

I compile, make a .jar file and put it into the ImageJ plugins folder. I can call it with the ImageJ userInterface (Plugin>Segmentation>Test) and the macro recorder will put the command used:

run("Test");

Then my code is executed, the log window pops-up as expected:

Starting plugin Test
args: ..

I can manually run the same command in a .ijm file, and get the same result. However, when I run the following macro command:

run("Test", "my_string");

I get the same results in the log window:

Starting plugin Test
args: ..  //  <- I would like to get "my_string" passed there 

Where it should have displayed (at least what I expect it to do)

Starting plugin Test
args: .my_string. 

So my question is: how can I pass parameters to PlugIn and especially how to access them? Many thanks


EDIT


Hey I found a way to bypass that:

Using the Macro.getOptions() : this method will retrieve the string passed in argument to the plugin. However, I still can't find a way to pass more than 1 string argument. I tried overloading the PlugIn.run() method but it doesn't work at all.

My quick fix is to put all my arguments in 1 string, and separating them by a space. Then I split this string:

String [] arguments = Macro.getOptions().split(" ");

I don't see a more convenient way to get around that. I can't believe how stupid this situation is.

Please, if you have a better solution, feel free to share! Thanks

役に立ちましたか?

解決

You are confusing the run(String arg) method in ij.plugin.Plugin with the ImageJ macro command run("command"\[, "options"\]), which calls IJ.run(String command, String options).

In the documentation for ij.plugin.Plugin#run(String arg), it says:

This method is called when the plugin is loaded. 'arg', which may be blank, is the argument specified for this plugin in IJ_Props.txt.

So, arg is an optional argument that you can use in IJ_Props.txt or in the plugins.config file of your plugin to assign different menu commands to different functions of your plugin (see also the excellent documentation on the Fiji wiki).

To make use of the options parameter when running your plugin from macro code, you should use a GenericDialog to get the options, or (as you apparently learned the hard way) use the helper function Macro.getOptions().

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top