Returning a value from a plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Returning a value from a plugin

Gabriel Landini
 Just a quick question

Can a plugin return a value? Or is that a bad idea?

If one could, how would one access that value from a macro?

Thanks

Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: Returning a value from a plugin

dscho
Hi,

On Fri, 3 Apr 2009, Gabriel Landini wrote:

>  Just a quick question
>
> Can a plugin return a value? Or is that a bad idea?
>
> If one could, how would one access that value from a macro?

The easiest method is to use a static variable, together with a static
function that you call through "call()".

This is not thread-safe, though...

Ciao,
Dscho
Reply | Threaded
Open this post in threaded view
|

Re: Returning a value from a plugin

cihat eldeniz
In reply to this post by Gabriel Landini
Just a small workaround coming to my mind: I believe you could use the
setProperty function of ImagePlus to embed any value into the image that
you would like to access later. I have no experience with the macro
language but I assume that you can readily access the image properties
through that language.

Thanks.

Gabriel Landini wrote:

>  Just a quick question
>
> Can a plugin return a value? Or is that a bad idea?
>
> If one could, how would one access that value from a macro?
>
> Thanks
>
> Gabriel
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: Returning a value from a plugin

Michael Schmid
In reply to this post by Gabriel Landini
Hi Gabriel,

if your plugin has a static method returning a string you can access  
it with the macro 'call' command.
E.g. for the built-in static String ij.Prefs.get(String key, String  
default) method:

var myParameter = parseInt(("ij.Prefs.get",  
"mymacro.myparameter","42"));

This should also work with a user plugin.

The downside: storing a value in a static class variable and then  
accessing it in a static method is not multithread safe. So if you  
have an image that your plugin works on, it might make sense to pass  
the value via the image infos instead.

Michael
________________________________________________________________

On 3 Apr 2009, at 13:30, Gabriel Landini wrote:

>  Just a quick question
>
> Can a plugin return a value? Or is that a bad idea?
>
> If one could, how would one access that value from a macro?
>
> Thanks
>
> Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: Returning a value from a plugin

Gabriel Landini
In reply to this post by Gabriel Landini
Wayne, Dscho, Michael, Cihat
Many thanks for the suggestions!
Gabriel