SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Home / forum / Animation / Mel Scripts & Programming / optionMenu confusion
Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 10-12-2004, 01:54 AM   #1
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Unhappy 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;
}
Dann is offline   Reply With Quote
Old 10-12-2004, 04:47 PM   #2
Nimmel
Registered User
 
Join Date: Aug 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
__________________
----------------------------------------------
Richard Cheek
http://www.freelance-animation.com
----------------------------------------------
Nimmel is offline   Reply With Quote
Old 10-12-2004, 07:04 PM   #3
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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
Dann is offline   Reply With Quote
Old 11-12-2004, 12:39 AM   #4
Nimmel
Registered User
 
Join Date: Aug 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
__________________
----------------------------------------------
Richard Cheek
http://www.freelance-animation.com
----------------------------------------------
Nimmel is offline   Reply With Quote
Old 11-12-2004, 02:18 AM   #5
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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 is offline   Reply With Quote
Old 13-12-2004, 11:02 PM   #6
Dann
Registered User
 
Dann's Avatar
 
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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!!!
Dann is offline   Reply With Quote
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.