user3295674
user3295674

Reputation: 913

MEL function call when radio button selected

I solved it by clearing keyframes at points, I will post my solution when the site lets me. Thanks for your thoughts!

Pretty new to MEL!

I wrote this function that, if radio button 1 is selected, it rotates ball 1 and then animates it (call to the oneballanim function).

On the other hand, if radio button 2 is selected, it rotates the two balls and then calls the function that animates both of them.

 global proc rotaterandanim() {
     if (`radioButtonGrp -q -select myRadBtnGrp` == 1) setAttr ball1.rotateZ 15;
     if (`radioButtonGrp -q -select myRadBtnGrp` == 1) oneballanim();

     //second radio button
     if (`radioButtonGrp -q -select myRadBtnGrp` == 2) setAttr ball1.rotateZ 15;
     if (`radioButtonGrp -q -select myRadBtnGrp` == 2) setAttr ball2.rotateZ 15;
     if (`radioButtonGrp -q -select myRadBtnGrp` == 2) twoballanim();         
 }

The problem is that when I run the script, it actually animates and moves BOTH balls, even when radio button 1 is selected!! What can I do to fix that?

Upvotes: 0

Views: 999

Answers (1)

Zak44
Zak44

Reputation: 350

You likely have something else going on here that is not easy to see without seeing the rest of the code. Just a suggestion, you should consolidate your IF/ELSE statements (see below). I tried the following, and it seemed to catch each selection fine without doing both at the same time (which is why I said there is something else going on here that we can't see without more code). Try the following... and keep executing rotaterandanim() after you select the button 1 or 2 each time, it prints out properly and only rotates what should rotate.

//    Create a window with two separate radio button groups.
//
string $window = `window`;
columnLayout;
radioButtonGrp  -numberOfRadioButtons 2
    -label "Two Buttons" -labelArray2 1 2
    -select 1
    myRadBtnGrp;
showWindow $window;

global proc rotaterandanim() {
    if (`radioButtonGrp -q -select myRadBtnGrp` == 1) {
        setAttr ball1.rotateZ 15;
        oneballanim();
    }
    //second radio button
    else if (`radioButtonGrp -q -select myRadBtnGrp` == 2) {
        setAttr ball1.rotateZ 15;
        setAttr ball2.rotateZ 15;
        twoballanim();  
    }       
}

global proc oneballanim() {
    print("OneBallAnim");
}

global proc twoballanim() {
    print("TwoBallAnim");
}

Upvotes: 0

Related Questions