global variables -- access by macro

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

global variables -- access by macro

Thomas Binder
Hello

I have been trying for a log time to get global variables work in a macro

There is a recommendation to define the variables in
"StartupMacros.txt", after that they may be available.

But if I try to print the variable

<pencilWidth>

which is defined in the default StartupMacro.txt after fresh
installation of ImageJ

(  var pencilWidth=1,  eraserWidth=10, leftClick=16, alt=8; )

after fresh startup of ImageJ

I get an error message:
-----------------------------------------------
Undefined variable in line ...
print ( <pencilWidth> );
-----------------------------------------------

Why ?

Please help

Thomas Binder
Reply | Threaded
Open this post in threaded view
|

Re: global variables -- access by macro

Michael Schmid
Hi Thomas,

as far as I can say you can't have global variables across different macro files, only within one macro file.
The way out would be using the ImageJ Preferences to store these values (as long as they are not arrays):

write:
 call("ij.Prefs.set", "myMacros.myValue",toString(myVariable));

read (with default 999)
 var myVariable = parseInt(call("ij.Prefs.get", "myMacros.myValue","999"));


Obviously, you don't need the 'toString' and 'parseInt' for Strings, and you should use parseFloat instead parseInt if you don't expect integers.

Michael
________________________________________________________________
On Apr 5, 2012, at 19:41, Thomas Binder wrote:

> Hello
>
> I have been trying for a log time to get global variables work in a macro
>
> There is a recommendation to define the variables in "StartupMacros.txt", after that they may be available.
>
> But if I try to print the variable
>
> <pencilWidth>
>
> which is defined in the default StartupMacro.txt after fresh installation of ImageJ
>
> (  var pencilWidth=1,  eraserWidth=10, leftClick=16, alt=8; )
>
> after fresh startup of ImageJ
>
> I get an error message:
> -----------------------------------------------
> Undefined variable in line ...
> print ( <pencilWidth> );
> -----------------------------------------------
>
> Why ?
>
> Please help
>
> Thomas Binder