FORUMS: list search recent posts

Radio Button Script Without Button

COW Forums : Autodesk Maya

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Jacqueline Johnsen
Radio Button Script Without Button
on Dec 27, 2011 at 2:00:12 pm

I want a simple script to turn the visibility of an object on and off. I actually have it working, but I want to get rid of one extra step. Which is the button. However Maya doesn't seem to like the "-command" in the radioButtonGrp. So if someone knows the solution please let me know... ^^

This script uses a cube mesh named pCube1

if ( `window -exists MyWindow` ) {
deleteUI MyWindow;
window -title "new window" -widthHeight 300 200 MyWindow;
formLayout -numberOfDivisions 100 myForm;
-numberOfRadioButtons 2
-label "select type"
-labelArray2 "Off" "On"
-select 1
button -label "Get Rid of this Button" -command "visibilityCube()" myBtn1;
formLayout -edit
-attachForm myRadBtnGrp "top" 10
-attachForm myRadBtnGrp "left" -50
-attachForm myBtn1 "bottom" 10
-attachForm myBtn1 "left" 10

showWindow MyWindow;
global proc visibilityCube() {
if (`radioButtonGrp -q -select myRadBtnGrp` == 1) setAttr pCube1.visibility 0;
if (`radioButtonGrp -q -select myRadBtnGrp` == 2) setAttr pCube1.visibility 1;

Return to posts index

Rob Dahl
Re: Radio Button Script Without Button
on Dec 27, 2011 at 4:28:28 pm

There are comments in the code to help.
Removed myBtn1 from the radio group and the form layout.
Added attribute to run Global procedure when the status to the radio group is changed.

To be more correct, change the code for the "-select 2" to an if statement that checks the actual visibility status of the pcube1 (or selected object). "2" represents the on position which I changed from "1" since this was to run when the cube was on screen.

Hope this helps.

Rob Dahl
Transparent Alchemy
Boulder City, NV 89005

Return to posts index

Jacqueline Johnsen
Re: Radio Button Script Without Button
on Jan 4, 2012 at 2:43:57 pm

Yeah, that works, thanks a lot!
So, why do I need a -change command and doesn't -command work? :/
I used the -command with a global procedure somewhere else and it worked just fine...
Anyway, thanks again! ^^

Return to posts index

Steve Sayer
Re: Radio Button Script Without Button
on Jan 4, 2012 at 4:28:31 pm

The 'radio button group' control simply doesn't understand the '-command' flag.

Different controls have different functions, just like different nodes have different attributes. A polyCube node doesn't have a "radius" attribute but a polySphere node does; if you tried to use MEL to create a cube and use a '-radius' flag you'd get an error.

In the same way, if you try to create a radio button group control and specify a '-command' flag, you'll get an error because that type of control just doesn't know what '-command' means. Rob's solution with the '-changeCommand' flag is what you were looking for. The reasoning behind naming it something different is that you have more options with a set of radio buttons than you do with a single button. A single button can only be clicked, so it only has the '-command' flag. But a set of radio buttons is more complex; you might want different buttons to do different things, you might want different commands for the 'on' and 'off' states for each, etc., so it has the following series of flags:


Check your Technical Documentation for an explanation of what they all do. In general, you should always be referring to the documentation for each MEL command you use; you can't assume that a flag you've used in one command previously will also be useful in a new command.

Hope that helps!


Return to posts index

Jacqueline Johnsen
Re: Radio Button Script Without Button
on Jan 5, 2012 at 12:01:01 pm

Ah yes, that does make sense. I just never tought there would be more than one command.
I do use the Autodesk melscript help, but rarely find my solution there unless it's for something simple like -minValue instead of -min. I just don't understand half of it because I'm not a programmer. :/
I get by, by randomly messing arround in the scripts, googling and using the script editor history. ^^

Got this script working with 3 radiobuttons and altering the height of an object now. \o//
Again thanks! ^^

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 All Rights Reserved