User input for a global variable in a macro?

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

User input for a global variable in a macro?

Bill Mohler
Can a macro be used to define a global variable for other macros
within the same file?  In other words, can a macro request a number
from the user in a dialog and then set assign that value to a global
variable?  Or can global variables in macros only be hard-coded into
the text of the macro file?

Thanks,
Bill
Reply | Threaded
Open this post in threaded view
|

Re: User input for a global variable in a macro?

Michael Doube
Bill,

If I understand you correctly, then yes you can set global variables for
a set of macros. You define the variables at the beginning of the macro
outside any of the installable submacros.  An example:

var myNewVariable = "Hi Bill";

macro "Read [1]"{
        Dialog.create("Enter Text");
        Dialog.addMessage("Enter some text");
        Dialog.addString("Text:", myNewVariable, 12);
        Dialog.show();
        myNewVariable = Dialog.getString();
}

macro "Write [2]"{
        print(myNewVariable);
}

Cheers

Mike
Reply | Threaded
Open this post in threaded view
|

Re: User input for a global variable in a macro?

Bill Mohler
Moving the initial declaration to the head of the file completely
solved my problem. Thanks!

>Bill,
>
>If I understand you correctly, then yes you can set global variables
>for a set of macros. You define the variables at the beginning of
>the macro outside any of the installable submacros.  An example:
>
>var myNewVariable = "Hi Bill";
>
>macro "Read [1]"{
> Dialog.create("Enter Text");
> Dialog.addMessage("Enter some text");
> Dialog.addString("Text:", myNewVariable, 12);
> Dialog.show();
> myNewVariable = Dialog.getString();
>}
>
>macro "Write [2]"{
> print(myNewVariable);
>}
>
>Cheers
>
>Mike
Reply | Threaded
Open this post in threaded view
|

Re: User input for a global variable in a macro?

mmettlen
Related to this, I have a macro using:

Dialog.create("Intensity values");
Dialog.addNumber("C1min:", 2);
Dialog.addNumber("C1max:", 10);
Dialog.addNumber("C2min:", 2);
Dialog.addNumber("C2max:", 10);
...
Dialog.show();

a = Dialog.getNumber();
b = Dialog.getNumber();
c = Dialog.getNumber();
d = Dialog.getNumber();
....

As shown, each time I run the macro, the default values '2' and '10' are shown in the dialog box. Is there any way that the macro, when it runs the next time, replaces/recalls these values with the last user input (i.e. a, b, c, d, ....)?

Thx, Marcel
Reply | Threaded
Open this post in threaded view
|

Re: User input for a global variable in a macro?

jumpfunky
Hi!

I've done this by writing all settings in a string seperated by
";" ("value1;value2;...;valueN") and then writing it to a file
(File.saveString(...)) in the ij temp directory.

When I start the macro I restore the old values out of that file:
oldsettingsRAW
=File.openAsString(getDirectory("temp")+"mysettings.txt");
roidata = split(roidataRaw, ";");

value1 =  parseInt(roidata[0]);
value2 =  parseInt(roidata[1]);;
etc.

Cheers,
Thorsten



Am Freitag, den 24.01.2014, 09:23 -0800 schrieb mmettlen:

> Related to this, I have a macro using:
>
> Dialog.create("Intensity values");
> Dialog.addNumber("C1min:", 2);
> Dialog.addNumber("C1max:", 10);
> Dialog.addNumber("C2min:", 2);
> Dialog.addNumber("C2max:", 10);
> ...
> Dialog.show();
>
> a = Dialog.getNumber();
> b = Dialog.getNumber();
> c = Dialog.getNumber();
> d = Dialog.getNumber();
> ....
>
> As shown, each time I run the macro, the default values '2' and '10' are
> shown in the dialog box. Is there any way that the macro, when it runs the
> next time, replaces/recalls these values with the last user input (i.e. a,
> b, c, d, ....)?
>
> Thx, Marcel
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/User-input-for-a-global-variable-in-a-macro-tp3694344p5006267.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: User input for a global variable in a macro?

Cammer, Michael
In reply to this post by mmettlen
Try this.  It should work until the macros are reinstalled at which time they will be reset to the initial values.

// defined as globals at the very beginning

var a = 2;
var b = 10;
var c = 2;
var d = 10;

macro "Test globals" {

  Dialog.create("Intensity values");
  Dialog.addNumber("C1min:", a);
  Dialog.addNumber("C1max:", b);
  Dialog.addNumber("C2min:", c);
  Dialog.addNumber("C2max:", d);
  Dialog.show();

  a = Dialog.getNumber();
  b = Dialog.getNumber();
  c = Dialog.getNumber();
  d = Dialog.getNumber();

  print(a,b,c,d);
} // end macro

===========================================================================
Michael Cammer, Microscopy Core & Dustin Lab , Skirball Institute, NYU Langone Medical Center
Cell:  914-309-3270   Lab: 212-263-3208
http://ocs.med.nyu.edu/microscopy & http://www.med.nyu.edu/skirball-lab/dustinlab/


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of mmettlen
Sent: Friday, January 24, 2014 12:23 PM
To: [hidden email]
Subject: Re: User input for a global variable in a macro?

Related to this, I have a macro using:

Dialog.create("Intensity values");
Dialog.addNumber("C1min:", 2);
Dialog.addNumber("C1max:", 10);
Dialog.addNumber("C2min:", 2);
Dialog.addNumber("C2max:", 10);
...
Dialog.show();

a = Dialog.getNumber();
b = Dialog.getNumber();
c = Dialog.getNumber();
d = Dialog.getNumber();
....

As shown, each time I run the macro, the default values '2' and '10' are shown in the dialog box. Is there any way that the macro, when it runs the next time, replaces/recalls these values with the last user input (i.e. a, b, c, d, ....)?

Thx, Marcel



------------------------------------------------------------
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email.
=================================

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: User input for a global variable in a macro?

mmettlen
Thanks - Michael Cammer's method works best for me, as I always got an "access denied' error message using jumpfunky's method (despite the saving-location being accessible)