Dialog.addChoice with Variables / Variables in an Array?

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

Dialog.addChoice with Variables / Variables in an Array?

rayh
Hi!
I'm setting up a macro in which the user is supposed to choose the applied file via a popup menu, as in this exemplary snippet:

Green = "File1";
Red = "File2";
choices = newArray("Green", "Red");
Dialog.create("Test");
Dialog.addChoice("Slide 1", choices);
Dialog.show();
Result = Dialog.getChoice();
print(Result);

The filepaths are set as variables, and I'd like the user's choice in the dialog to translate into the string of the respective variable, i.e. choosing "Green" or "Red" in the dialog is supposed to print "File1" or "File2", respectively -but instead I only recieve "Green" or "Red". How can I make the macro utilize the strings from the appropriate variables?

-Ray



Reply | Threaded
Open this post in threaded view
|

Re: Dialog.addChoice with Variables / Variables in an Array?

Gabriel Landini
On Wednesday 30 Jul 2014 06:08:38 you wrote:

> Hi!
> I'm setting up a macro in which the user is supposed to choose the applied
> file via a popup menu, as in this exemplary snippet:
>
> Green = "File1";
> Red = "File2";
> choices = newArray("Green", "Red");
> Dialog.create("Test");
> Dialog.addChoice("Slide 1", choices);
> Dialog.show();
> Result = Dialog.getChoice();
> print(Result);
>
> The filepaths are set as variables, and I'd like the user's choice in the
> dialog to translate into the string of the respective variable, i.e.
> choosing "Green" or "Red" in the dialog is supposed to print "File1" or
> "File2", respectively -but instead I only recieve "Green" or "Red". How can
> I make the macro utilize the strings from the appropriate variables?

Green is a variable, "Green" is a string, so change the above to:

choices = newArray(Green, Red);

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

Re: Dialog.addChoice with Variables / Variables in an Array?

rayh
Gabriel Landini wrote
Green is a variable, "Green" is a string, so change the above to:

choices = newArray(Green, Red);
Thanks for your reply, but I already tried that, and when I do so the choices in the dialog box are both shown as "NaN", and I also recieve "NaN" from the print function. Unfortunately I didn't find any information if arrays are generally able to list variables. By chance, does anyone know if there's a possibility to somehow 'render' a string to a respective variable inside a macro?
Reply | Threaded
Open this post in threaded view
|

Re: Dialog.addChoice with Variables / Variables in an Array?

Gabriel Landini
On Wednesday 30 Jul 2014 07:54:49 you wrote:
> Gabriel Landini wrote
>
> > Green is a variable, "Green" is a string, so change the above to:
> >
> > choices = newArray(Green, Red);
>
> Thanks for your reply, but I already tried that, and when I do so the
> choices in the dialog box are both shown as "NaN", and I also recieve "NaN"
> from the print function.

So strange. Your modified example works fine here.

Green = "File1";
Red = "File2";
choices = newArray(Green, Red);
Dialog.create("Test");
Dialog.addChoice("Slide 1", choices);
Dialog.show();
Result = Dialog.getChoice();
print(Result);

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

Re: Dialog.addChoice with Variables / Variables in an Array?

ctrueden
Hi Ray,

> I'd like the user's choice in the dialog to translate into the string
> of the respective variable, i.e. choosing "Green" or "Red" in the
> dialog is supposed to print "File1" or "File2"

How about this?

--snip--
files = newArray("File1", "File2", "Shazam");
choices = newArray("Green", "Red", "Blue");
Dialog.create("Test");
Dialog.addChoice("Slide 1", choices);
Dialog.show();
result = Dialog.getChoice();
for (i=0; i<choices.length; i++) {
if (result == choices[i]) {
file = files[i];
break;
 }
}
print(file);
--snap--

-Curtis


On Wed, Jul 30, 2014 at 10:04 AM, Gabriel Landini <[hidden email]>
wrote:

> On Wednesday 30 Jul 2014 07:54:49 you wrote:
> > Gabriel Landini wrote
> >
> > > Green is a variable, "Green" is a string, so change the above to:
> > >
> > > choices = newArray(Green, Red);
> >
> > Thanks for your reply, but I already tried that, and when I do so the
> > choices in the dialog box are both shown as "NaN", and I also recieve
> "NaN"
> > from the print function.
>
> So strange. Your modified example works fine here.
>
> Green = "File1";
> Red = "File2";
> choices = newArray(Green, Red);
> Dialog.create("Test");
> Dialog.addChoice("Slide 1", choices);
> Dialog.show();
> Result = Dialog.getChoice();
> print(Result);
>
> --
> 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: Dialog.addChoice with Variables / Variables in an Array?

rayh
In reply to this post by Gabriel Landini
Gabriel Landini wrote
So strange. Your modified example works fine here.
Ok, seems to be a problem related to the ImageJ version. The NaN stuff occured on 1.43m, when I run it on 1.48v it workes -though unfortunately not exactly as I wanted: Now File1 / File2 gets displayed in both the dialog and the print log, but I'd like the dialog to show Green and Red, while the print should yield File1 / File2. Is that possible?
Reply | Threaded
Open this post in threaded view
|

Re: Dialog.addChoice with Variables / Variables in an Array?

rayh
In reply to this post by ctrueden
Curtis Rueden wrote
How about this?

--snip--
[...]
--snap--

-Curtis
Thanks a lot, that actually worked fine for me!