Mar 2011
1 / 7
Mar 2011
Mar 2011

This is the same post i did earlier, but now with cry for help :stuck_out_tongue:

Hi everybody,

I've just entered the world of Mel scripting and i'm trying to create a on/off switch in Mel. It is for switching certain controls visibility on and off. They have been keyed with set driven key under one attribute  "AdvFootControl"

I tryed using a if else statement, but it just doesn't do what I want to do. What am I doing wrong???

if("right_Foot_Ctrl.AdvFootControl" == 0)

{

setAttr "right_Foot_Ctrl.AdvFootControl"  1;

}

else

{

setAttr "right_Foot_Ctrl.AdvFootControl"  0;

}

It goes from on too off mode but it won't return it from off too on mode!?

%P

Thnx in advance :smiley:


I know now the above function won't work soo I tryed this:

if("right_Foot_Ctrl.AdvFootControl" == 0){

setAttr "right_Foot_Ctrl.AdvFootControl"  1;

}else{

if("right_Foot_Ctrl.AdvFootControl" == 1){

setAttr "right_Foot_Ctrl.AdvFootControl"  0;

}

}

But now it won't work at all!?


Now I tryed this:

if("right_Foot_Ctrl.AdvFootControl" == 0){

setAttr "right_Foot_Ctrl.AdvFootControl"  1;

}

else if ("right_Foot_Ctrl.AdvFootControl" == 1){

setAttr "right_Foot_Ctrl.AdvFootControl"  0;

}

and it doesn't WORK  *(

  • created

    Mar '11
  • last reply

    Mar '11
  • 6

    replies

  • 3.7k

    views

  • 1

    user

  • 1

    like

if im thinking what your thinking then the reason those scripts wont work is because your saying if "right_Foot_Ctrl.AdvFootControl" is OFF then turn it ON and vice-versa.

if that was a mistake and you meant (eg)
"
if("right_Foot_Ctrl.AdvFootControl" == 0){

setAttr "right_Foot_Ctrl.visibility"  1;

}

"

then that wont work is because those mel scripts are not always evaluating. what it means is, the script only runs when you press excute.

few ways to solve this, including scriptJobs, expressions and nodes.

most secure way would be with nodes, use your hypergraph to connect  "right_Foot_Ctrl.AdvFootControl" to a reverse utility node then the output of the reverse node to "right_Foot_Ctrl.visibility".

Hi IdunHam1,

This Mel-script wil be put on a shelf. I'm trying to create a rig that is easy
accessible for animators who have never worked with a 3D tool. The shelf
while be a quick and visual way of accessing curtain functions of the rig.

So press the button on the shelf > check if it is on or off, and than turn it off
or on.

So I thought this would work, but somehow it does't:

if("right_Foot_Ctrl.AdvFootControl" == 0){

setAttr "right_Foot_Ctrl.AdvFootControl"  1;

}

else if ("right_Foot_Ctrl.AdvFootControl" == 1){

setAttr "right_Foot_Ctrl.AdvFootControl"  0;

}

oh sorry, i got the wonrg end of the stick there.

try;

float $R_afc = getAttr right\_Foot\_Ctrl.AdvFootControl ;
if ($R_afc != 0)
{
    setAttr right_Foot_Ctrl.AdvFootControl  0 ;
}

else
{
    setAttr right_Foot_Ctrl.AdvFootControl  1 ;

problem is you cant just get an attributes value without using specific commands, so you query the attribute with "getAttr", store value into a float then use that with the "if" function instead. i thinki it might be because an attribute can have many different values other that what you see, you need to specify what information about that attribute you want.
its a bit of a pain but it works lol.

[b]It works, sweet!! :stuck_out_tongue:

Thnx for the help and time, i appreciate it :D[/b]

One more thing, in the condition part of the " if " statement
you've put down a exclamation mark ($R_afc != 0), what's that for?

  !=    means  "not equal to"  and   ==    means "equal to"

i couldve used " == 1" but i prefer using   !=   instead. its just something useful to know.

no probs, anytime. :slight_smile: 

Once you know that ! means not you suddenly realize you can condense the code to:

setAttr right_Foot_Ctrl.AdvFootControl  (!getAttr right\_Foot\_Ctrl.AdvFootControl) ;