Posted by
CARL Philippe (LBP) on
Jun 16, 2016; 10:05am
URL: http://imagej.273.s1.nabble.com/launch-functions-in-java-tp5016624p5016658.html
Hi Michael,
How are you doing? (I hope you have a better weather than what we get here!!!)
I thank you very much for your answer that helped me to understand a couple of things.
So first to solve the macro extension issue (i.e. get rid of the "Macro must be running to install macro extensions" error) when launching the plugin form another plugin, I have added a "Interpreter.getInstance()" condition and now everything works fine by using the following code:
if (!IJ.macroRunning() || Interpreter.getInstance() == null)
{
IJ.error("Cannot install macro extensions from outside a macro!");
return;
}
else
Functions.registerExtensions(this);
Nevertheless, I still have some issues for "calling a plugin from other plugins".
Indeed, if I have the following plugin file (Call_Demo.java):
public class Call_Demo
{
public static String method1(String arg1)
{
return "method1"+"("+arg1+")";
}
}
That I call with the following plugin:
import ij.*;
import ij.plugin.*;
public class My_Plugin implements PlugIn
{
public void run(String arg)
{
IJ.log(Call_Demo.method1("arg1"));
}
}
Everything is working fine: i.e. I get the result "method1(arg1)" within the log window.
But when I put the Call_Demo.java file in a folder named "test" and add the line:
package test;
within the plugin code.
In this case, I'm able to correctly compile the new Call_Demo.java file, but as I expected that I need to change the
IJ.log(Call_Demo.method1("arg1"));
line into
IJ.log(test.Call_Demo.method1("arg1"));
this is not working and giving me the error: "package test does not exist".
Knowing that the final goal is to launch the Call_Demo.method1 from within a jar file similar to the one you can find under the link:
http://punias.free.fr/ImageJ/arf_.jarDo you have an idea of what I'm doing wrong and should correct?
I thank you very much in advance for your help.
Kindest regards,
Philippe
-----Message d'origine-----
De : ImageJ Interest Group [mailto:
[hidden email]] De la part de Michael Schmid
Envoyé : mercredi 15 juin 2016 10:23
À :
[hidden email]
Objet : Re: launch functions in java
Hi Philippe,
as I said, I have no experience with macro extensions. There is a bit of documentation at
https://imagej.nih.gov/ij/macros/MacroExtensions.txtOne obvious way of accessing macro extensions in a plugin would be calling a short macro by
IJ.runMacro(String macro)
Concerning public methods: For calling a plugin from other plugins, I
think this should be obvious. A macro can call only static methods:
https://imagej.nih.gov/ij/developer/macro/functions.html#callThis method can also return a String.
An example for calling a static function is my Versatile_Wand:
http://imagejdocu.tudor.lu/doku.php?id=plugin:segmentation:versatile_wand:startIt can be called via
call("Versatile_Wand_Tool.doWand", x, y, tolerance, colorSensitivity,
gradientTolerance, "options");
and the plugin has a method
public static void doWand(String xStartS, String yStartS,
String toleranceS, String colorS, String gradientS, String options)
In this method, the strings are converted (parsed) to numbers where
appropriate, and then a new instance of the plugin is created and gets
the arguments to do the work.
Michael
________________________________________________________________
On 2016-06-13 14:50, Philippe CARL wrote:
> Hi Michael,
> How are you doing?
> I had finally figured out the first version (i.e. with the
> imp.show()
added after each IJ.openImage) but the alternative version is what I was
actually looking for (to be faster since the pictures are not shown).
> Nevertheless, I didn't expect the needed code to be so complicated,
thus thanks a lot for sharing it!!!
> I can modify the plugin I working on, thus all options are open and
> Iwould prefer to choose the most adapted and efficient one.
> Also would you have an example to link me with where there is a
"public method of the plugin that gets called"?
> The issue is that the plugin has already " ij.macro.MacroExtension"
features and when I try to launch it through a "IJ.run" I get the "Macro
must be running to install macro extensions" error which corresponds to
the case (interp==null) of the "registerExtensions" method within the "
ij.macro.Functions.java" class.
> Which obviously means that I'm doing something wrong here and I'm
> kindof stuck...
> I thank you very much in advance for your help. > Kindest regards,
> Philippe
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html