I've been searching around for this a bit and can't find anything.
How can i return a value from a plugin to a macro? I've got a lot of analysis plugins and would like to perform various things with the return values in a macro. thanks in advance Gabe |
Hi Gabe,
there are several possibilities: - have a static method of your plugin that returns a String. You can access it by the call macro function - via the Results Table - by setting pixels in an image created for this putpose (if you want to access an array) - via a file Michael ________________________________________________________________ On 16 Oct 2009, at 14:20, gabejackson wrote: > I've been searching around for this a bit and can't find anything. > > How can i return a value from a plugin to a macro? I've got a lot of > analysis plugins and would like to perform various things with the > return > values in a macro. > > thanks in advance > > Gabe |
Hi Bill, Gabe,
ok, a bit more specific: For transferring parameters/data *to* a plugin, the usual way is via GenericDialog (also recordable in a macro), as almost all built-in ImageJ commands do. Of course, you can also use static methods that set static variables for this purpose. For transferring data *from* a plugin, setting a static variable and having a static method to return it is a reasonable choice (especially if there are reasons for not using the Results Table). Of course, static methods are not multithread-safe. Example: In your plugin, you have, e.g.: public class My_Plugin extends ... { static double myResult; void run(ImageProcessor ip) { ... myResult = ...; } static String getResult() { return myResult.toString(); } } In the macro myResult = parseFloat(call("My_Plugin.getResult")); Michael ________________________________________________________________ > > Michael Schmid wrote: >> >> Hi Gabe, there are several possibilities: - have a static method >> of your plugin that returns a String. You can access it by the >> call macro function - via the Results Table - by setting pixels in >> an image created for this putpose (if you want to access an array) >> - via a file Michael >> ________________________________________________________________ >> On 16 Oct 2009, at 14:20, gabejackson wrote: >>> >>> I've been searching around for this a bit and can't find >>> anything. How can i return a value from a plugin to a macro? I've >>> got a lot of analysis plugins and would like to perform various >>> things with the return values in a macro. thanks in advance Gabe |
In reply to this post by Michael Schmid
Hi Gabe,
there is also another way I use/would suggest, you can either set an ImageJ property from the plugin and read it in the macro via (and vice/versa) call("ij.Prefs.get", "<propname>", <default>); or sometimes IMHO it makes more sense that the plugin attaches some specific properties to the images it processed or created, this can be read similarly with a simple plugin I once made: http://rsbweb.nih.gov/ij/plugins/imp-props.html I use this in some reader plugins for special file formats that attach extra properties to the images read so that other plugins or macros can interpret those Hope this helps! Joachim Michael Schmid <[hidden email] N.AC.AT> An Gesendet von: [hidden email] ImageJ Interest Kopie Group <[hidden email]. Thema GOV> Re: How to return a value from a plugin to a macro? 16.10.2009 14:34 Bitte antworten an ImageJ Interest Group <[hidden email]. GOV> Hi Gabe, there are several possibilities: - have a static method of your plugin that returns a String. You can access it by the call macro function - via the Results Table - by setting pixels in an image created for this putpose (if you want to access an array) - via a file Michael ________________________________________________________________ On 16 Oct 2009, at 14:20, gabejackson wrote: > I've been searching around for this a bit and can't find anything. > > How can i return a value from a plugin to a macro? I've got a lot of > analysis plugins and would like to perform various things with the > return > values in a macro. > > thanks in advance > > Gabe ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ |
In reply to this post by gabejackson
thanks a lot!
|
In reply to this post by Michael Schmid
Hi Michael,
I read this topic since it is exactly what I need to perform, and I'm trying to implement your method with static variable and call function from the macro. However, I got the following message error: cannot load class My_Plugin Any hints? Should I somehow "import" this class into my macro? Thank you Stefano Here is my plugin code: import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.filter.*; import java.io.*; public class Filter_CountWhitePoints implements PlugInFilter { ImagePlus imp; static int myResult; public int setup(String arg, ImagePlus imp) { this.imp = imp; return DOES_ALL; } public void run(ImageProcessor ip) { byte[] pixels = (byte[])ip.getPixels(); int[] pix = new int[pixels.length]; int counter=0; for (int i=0; i<(pixels.length); i++){ pix[i] = pixels[i] & 0xff; if (pix[i]==0){ counter++; } } myResult = counter; } static String getResult() { return Integer.toString(myResult); } } and the call from the macro (I run the plugin before asking for the return value): run("Filter CountWhitePoints"); var white = call("Filter CountWhitePoints.getResult");
|
I'm sorry, the message error is:
Could not load class "Filter CountWhitePoints" Friendly, Stefano <quote author="ce01"> Hi Michael, I read this topic since it is exactly what I need to perform, and I'm trying to implement your method with static variable and call function from the macro. However, I got the following message error: cannot load class My_Plugin Any hints? Should I somehow "import" this class into my macro? Thank you Stefano |
Free forum by Nabble | Edit this page |