PDA

View Full Version : controlling 2 attributes with 1 slider?



riseon
04-20-2011, 11:37 AM
Hello everybody,
it's the second day I use MEL in my whole life so be patient!
I'm creating a GUI for controlling a rigged character
I have 2 sliders, each one controlling an attribute.
I'd like to have a third slider controlling both attributes at the same time (or both sliders) possibly without using set driven key. Is that possible?
if it is how would you achieve it?

here's a part of what I have so far so you have an idea of what I'm talking about:

if (`window -exists myWindow`) { deleteUI -window myWindow; }
window -title "HARRY 1.0" -widthHeight 420 60 myWindow;
columnLayout;
attrFieldSliderGrp -label "L_emozioni" -min -25 -max 25 -at "left_struttura_palpebre.rx";
attrFieldSliderGrp -label "R_emozioni" -min -25 -max 25 -at "right_struttura_palpebre.rx";
button -label "RESET" -command "RESET";
showWindow myWindow;

Hope somebody can help me out!
Have a nice day
Fede

chrisg
04-20-2011, 12:20 PM
Hi riseon,

What type of movement do you want out of these sliders?

Let's call them SliderL, SliderR and SliderBoth. Right now, SliderL and SliderR set the attribute to that number. So if you set SliderL to 12, your rotation is set exactly to 12. Do you want the SliderBoth to modify the other sliders, or to overwrite them? So if you set SliderBoth to 5, do you want SliderL to be 17 or 5?

chrisg
04-20-2011, 12:36 PM
I was able to get the 2nd type of movement using expressions and custom attributes. I'm not sure if it's the most efficient solution, but it gives you the second type of movement.


if (`window -exists myWindow`) { deleteUI -window myWindow; }
window -title "HARRY 1.0" -widthHeight 420 60 myWindow;
columnLayout;
attrFieldSliderGrp -label "L_emozioni" -min -25 -max 25 -at "left_struttura_palpebre.SliderL";
attrFieldSliderGrp -label "R_emozioni" -min -25 -max 25 -at "right_struttura_palpebre.SliderR";
attrFieldSliderGrp -label "Both_emozioni" -min -25 -max 25 -at "right_struttura_palpebre.SliderBoth";
button -label "RESET" -command "RESET";
showWindow myWindow;


You'll need to add attributes to your two objects. These are just the MEL commands, but you can just go to Edit -> Add Attribute



addAttr -ln "SliderL" -at double |left_struttura_palpebre;
addAttr -ln "SliderBoth" -at double |left_struttura_palpebre;
addAttr -ln "SliderR" -at double |right_struttura_palpebre;


Then, here is the expression you need to create to tie it all together.


left_struttura_palpebre.rotateX = left_struttura_palpebre.SliderL + right_struttura_palpebre.SliderBoth
right_struttura_palpebre.rotateX = right_struttura_palpebre.SliderR + right_struttura_palpebre.SliderBoth

riseon
04-21-2011, 09:42 AM
thank you sooooo much man!
you just saved my life :)
Fede