Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   optionMenu confusion (https://simplymaya.com/forum/showthread.php?t=14663)

Dann 10-12-2004 02:54 AM

optionMenu confusion
 
I'm trying to create a script that uses an option menu, but I cannot figure out how to determine which menu item is currently selected by the user. I'm guesing I want to use -q or -pma, but I can't figure out what to do with them or what the syntax would be, not can I find anything in the docs to tell me.

Help!!

Thanks,
-dann


global proc optMenu2()
{

string $selected = "orange";

window -menuBar true -maximizeButton false -title "Option Menu" -iconName "optMenu2_I" -w 200 -h 150 optMenu2a_w;
columnLayout;

rowColumnLayout -numberOfRows 3;
optionMenu -label "Attributes" -q optMenu2a_w -cc "($selected = ???)";

menuItem -label "orange";
menuItem -label "blue";
menuItem -label "yellow";

showWindow optMenu2a_w;
}

Nimmel 10-12-2004 05:47 PM

You are right about the -q flag, simply use it with -v or -sl to get the result, however, you will need to know the name of the optionMenu to be able to do this. To get around this, name it yourself.

optionMenu -label "Attributes" TestMenu;

The above one forces the name to be TestMenu, so to get it's value use,

optionMenu -q -v TestMenu;

or you can get the value as a string by using the -sl flag.

optionMenu -q -sl TestMenu;



I hope this helps,

Richard

Dann 10-12-2004 08:04 PM

Thanks for the help, but I still don't get it. I tried this:

optionMenu -label "Attributes" -q -sl optionMenuName -cc $printSelected;

but I got errors saying that both -sl and -cc were invalid flags. Maybe I don't need the -cc, but that still doesn't explain why it claims those flags are invalid.

I also tried :
optionMenu -q -sl optionMenuName; , but I get the error
"Object not found: optionMenuName"

So in what way am I misunderstanding you?

-dann

Nimmel 11-12-2004 01:39 AM

When you set up the option menu, you don't need to -q flag because you are creating it, not querying it. Latter when you want to query it in another part of your code you use the -q flag.

For example;

global proc optMenu2()
{

string $selected = "orange";

window -menuBar true -maximizeButton false -title "Option Menu" -iconName "optMenu2_I" -w 200 -h 150 optMenu2a_w;
columnLayout;

rowColumnLayout -numberOfRows 3;
optionMenu -label "Attributes" optMenu2_Menu;

menuItem -label "orange";
menuItem -label "blue";
menuItem -label "yellow";

showWindow optMenu2a_w;
}


All I've changed here is the optionMenu line. I took out the -q and the -cc flags and named it optMenu2_Menu.
If you copy and past the above code into maya and then run it (type optMenu2), you will get your window. From here you can query the menu from the script editor by typing;

optionMenu -q -v optMenu2_Menu;

This should allow you to select a menu item and then use the script edit to query it.

If you want to set somthing up when the menu item is changed, this is when you use the -cc flag.

For example copy and paste in the code below to the script editor and then select a new item from the menu. The -cc flag runs the new proc PrintMenu() whenever the menu item changes. This new proc simply querys the menu and prints the results to the scipt editor (so have it open when you change somthing).



// Start Copy Here////////////////////////////////////////
///////////////////////////////////////////////////////////////

global proc PrintMenu()
{
string $MenuValue = `optionMenu -q -v optMenu2_Menu`;

print ("\n\nThe menu item is : " + $MenuValue );
}

global proc optMenu2()
{

if (`window -exists optMenu2a_w`)
deleteUI optMenu2a_w;

string $selected = "orange";

window -menuBar true -maximizeButton false -title "Option Menu" -iconName "optMenu2_I" -w 200 -h 150 optMenu2a_w;
columnLayout;

rowColumnLayout -numberOfRows 3;
optionMenu -label "Attributes" -cc "PrintMenu" optMenu2_Menu;

menuItem -label "orange";
menuItem -label "blue";
menuItem -label "yellow";

showWindow optMenu2a_w;
}

optMenu2;

// EndCopy Here//////////////////////////////////////////
///////////////////////////////////////////////////////////////


I hope this helps

Richard

Dann 11-12-2004 03:18 AM

Thanks Richard,

This will be very helpful. I won't be able to look at it until Monday, but I look forward to dissecting it then.

Dann 14-12-2004 12:02 AM

That was just what I needed to get me on the right path. Now all I need to do is plug it in with the rest of my script, get a few other UI things working, and I'm there. All downhill from here.

Thanks again!!!


All times are GMT. The time now is 07:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018