CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 10-22-2009, 03:31 AM   #1
TheRispo
legendary monkeytician
 
TheRispo's Avatar
portfolio
Jose Eduardo
Guadalajara, MX
 
Join Date: Oct 2009
Posts: 142
disabling a button with a checkbox

Hi everyone.. I finally gathered some courage and tackled UI building in MEL.. The issue here is:
I want a couple of intFields & textFields to be disabled until the user clicks on a checkbox. This way the user might add its own values instead of using the default ones...

My guess is that this might be achieved using the -onCommand and -offComand on the checkbox.. But being the total n00b I am, I can't figure it out how to make this thing turn on/off the -enable flag on the textfield.

I'll be thankfull if you guys can point me in the right direction.
 
Old 10-22-2009, 06:22 AM   #2
Buexe
Expert
 
Buexe's Avatar
portfolio
Jan Berger
Germany
 
Join Date: Apr 2003
Posts: 2,287
you can use the "-enable" flag to turn controls on or off. Just make sure you also use the "-edit" flag when you want to change the enable state of an existing control.
__________________
Digital Characters R&D - Suntoucher Labs
 
Old 10-22-2009, 07:01 AM   #3
Pyrokinesis
Frequenter
portfolio
Shaun Friedberg
Technical Director
Weta Digital
Wellington, NZ
 
Join Date: May 2006
Posts: 268
Here is a super simple example:

Code:
global proc openWindow(){ // If the window exists, delete it if (`window -exists toggleWin`) deleteUI toggleWin; // Declare the window and a couple options window -title "Toggle Window" -widthHeight 220 310 -maximizeButton off toggleWin; // Declare a layout for us to put a couple of controls columnLayout mainColumn; // Create our textField and checkbox // Give them variable names which we can use to query their attributes later // Tell the checkBox to do something when we change it's status textField -text "This is text" -width 150 myTxtField; checkBox -label "Toggle" -changeCommand toggleTxtEnable myCheckBox; // Show our Window showWindow toggleWin; } // Global Proc to toggle the enable state of the text field global proc toggleTxtEnable(){ // Query the enable state of the textField, notce how we use its name // If it "Is" enabled set enable to 0, else set enable to 1 if(`textField -q -enable myTxtField`){ textField -edit -enable 0 myTxtField; } else{ textField -edit -enable 1 myTxtField; } } // Initiate the Global Proc to launch our window openWindow();


As with everything in Maya there is always multiple ways to achieve the same result.
It's important not to think of one way as the magic bullet solution.

Good Luck.
__________________
Ok, But Can You Do It...ON FIRE!

Last edited by Pyrokinesis : 10-22-2009 at 07:05 AM.
 
Old 10-22-2009, 02:12 PM   #4
TheRispo
legendary monkeytician
 
TheRispo's Avatar
portfolio
Jose Eduardo
Guadalajara, MX
 
Join Date: Oct 2009
Posts: 142
Thanks for the help guys! it works great... I guess I was barking at the wrong tree there with the -onCommand and -offCommand.
Thanks again
 
Old 10-22-2009, 08:07 PM   #5
efecto
FX fan
 
efecto's Avatar
portfolio
Dice
FX 4 life
New Zealand
 
Join Date: May 2006
Posts: 218
Quote:
Originally Posted by TheRispo
Thanks for the help guys! it works great... I guess I was barking at the wrong tree there with the -onCommand and -offCommand.
Thanks again


You can use those flags too.

eg)
-onCommand textOn
-offCommand textOff

proc textOn {
// turn on the text, text -e -en 1
}

proc textOff {
// turn off text, text -e -en 0, there should be a flag to control visibility too
}
 
Old 10-22-2009, 08:44 PM   #6
TheRispo
legendary monkeytician
 
TheRispo's Avatar
portfolio
Jose Eduardo
Guadalajara, MX
 
Join Date: Oct 2009
Posts: 142
Thanks for the reply efecto, Its great to learn diferent ways to achieve the same thing.
 
Old 10-23-2009, 08:53 AM   #7
ewerybody
wt
 
ewerybody's Avatar
portfolio
eRiC Werner
pyroTechnical Artist
Berlin, Germany
 
Join Date: Jun 2003
Posts: 613
here is one more magic bullet:

Code:
window; columnLayout; button -label "Ok!" theButton; checkBox -v 1 -cc "button -e -en #1 theButton"; showWindow;


Use the #1-placeholder which stands for the current value of the control. Of course this is more pain in the a if you try to stuff more elements into the -changeCommand (-cc) but you could also en-/disable a layout which holds all the controls you want to switch.
__________________
goodsoul.de
 
Old 10-23-2009, 05:01 PM   #8
TheRispo
legendary monkeytician
 
TheRispo's Avatar
portfolio
Jose Eduardo
Guadalajara, MX
 
Join Date: Oct 2009
Posts: 142
Great.. thanks for that!!

I didnt know that #1 would have such a function... Does a more in depth explanation of that comes in the docs?? or is it kind of basic coding knowledge?? sorry if its a question to basic, but my only coding knowledge comes from particle expresions and simple "proceduraly-build-your-own-stairs" scripts... nothing UI related.

Thanks
 
Old 10-24-2009, 07:36 AM   #9
ewerybody
wt
 
ewerybody's Avatar
portfolio
eRiC Werner
pyroTechnical Artist
Berlin, Germany
 
Join Date: Jun 2003
Posts: 613
I doubt that you find much more about that in the docs.. Its actually very simple. #1,#2 or #3 .. in a command at a control is replaced with the current value of the control. At controls with multiple inputs there is #2,#3 for the other ones..

instead you could also write:

Code:
window; columnLayout; button -label "Ok!" theButton; checkBox -v 1 -cc "button -e -en (`checkBox -q -v theCheckBox`) theButton" theCheckBox; showWindow;


So the controls asks itself what value it currently has. You need to name it then and the string is much longer. But wurks as well. One issue I experienced: if you use #1 at textFields entered quote signs are not properly passed.
__________________
goodsoul.de
 
Old 10-24-2009, 04:00 PM   #10
TheRispo
legendary monkeytician
 
TheRispo's Avatar
portfolio
Jose Eduardo
Guadalajara, MX
 
Join Date: Oct 2009
Posts: 142
thanks for the explanation ewerybody, I think its much clearer now.
Thanks for the help
 
Old 10-24-2009, 04:00 PM   #11
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,480
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:25 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.