View Full Version : Connect a slider

10 October 2003, 01:01 PM

Can you help me about my little question ?

Can I connect a slider ( value min 0 - max 10 ) with a bone rotate att. ( value rY 90 - rY 145 ).

I want to do this;
When I set the slider "0" the bone rotation Y should be 90 and when I set the slider "10" the bone rotation Y should be 145.

Is this possible ?

10 October 2003, 04:24 PM
you could create a custom attr for the bone, control that with the slider. then use Set Driven Key to make the attr control the bone. SDK auto-magically replaces the 90-145 with the 0-10, based on your keys. You can even go back and edit the keys in the graph editor.

10 October 2003, 06:41 PM
I always create custom att. for my complex characters. In a complex rig, a character needs lots of custom att. You know. I don't want to create custom att. every complex rig. Sometimes this job is very boring.

I am trying to do a short connection something like that.

Thank you.

10 October 2003, 07:14 PM
you could write an expression that did the conversion in one step. I don't think that would be too complex, but it would be some math to convert the numbers.

or, the slider could just go from 90 to 145, using the minValue and maxValue flags. not so pretty for the user, but easier for the developer...

overall though, I'd guess that SDK would be the best solution.

Do post if you find an interesting method though, I'd like to know about anything to make life easier:)

10 October 2003, 07:17 AM
Thank you for your suggestions

I try create an expression. But I can't do it without problems. :scream: Should be a short way ...

10 October 2003, 08:50 AM

slider_max= 10

bone.ry = 90

slider has a span of 10 units, bone.ry has a span of 55 units. than means 1 slider unit = 5.5 bone.ry units
So I guess the formula would be:

bone.ry = 90 + (sliderValue * 5.5);


10 October 2003, 08:56 AM
alesmav, Thank you so very much. This is very simple.
:eek: :thumbsup:

10 October 2003, 09:09 AM
but I don't know how can I connect this code with the slider.

this is my simple code;
floatSliderGrp -min 0 -max 10 -field true -width 30 L_Wrist_T; connectControl L_Wrist_T aha.ry;

10 October 2003, 09:35 AM
try this in the expression window:

float $sliderValue = `floatSliderGrp -q -v L_Wrist_T`;

bone.ry = 90 + ($sliderValue *5.5);

Change the names if necessary...

lemme know if it works...


10 October 2003, 10:06 AM
I changed the name. It is not working , becasue aha.ry is connected with exp. and the slider can't control aha.ry
aha.ry is always wait on 90.

float $sliderValue = `floatSliderGrp -q -v L_Wrist_T`;
aha.ry = 90 + ($sliderValue *5.5);

10 October 2003, 11:50 AM
What expression is aha.ry connected to? Is there another expression?


10 October 2003, 12:17 PM
Fisrtsly I execute the exp:

float $sliderValue = `floatSliderGrp -q -v L_Wrist_T`;
aha.ry = 90 + ($sliderValue *5.5);
When I execute the exp. aha.ry connect with the exp.

and I move slider to new location ( 0 to 10 ) but the bone not rotate.

There is no any other exp.

And I am new in MEL :)

10 October 2003, 08:11 PM
sorry, but I am not at home right now and won't be until sunday evening. I have the whole code at home, and if it's not too late I will post it on sunday...


10 October 2003, 07:11 AM
Thank you for your interest. I will be waiting for your post.

10 October 2003, 09:43 AM
Meanwhile I can give you some tips, cos I see you do mel scripting. I was wrong, you don't have to write anything in the expression window. Everything is done in a script.

So you have your UI window with a floatSliderGrp. You said that the command was:

floatSliderGrp -min 0 -max 10 -field true -width 30 L_Wrist_T;

if you said that the bone needs to rotate from 90 to 145, why don't you make a min and max value of the slider 90 and 145?
Now you don't have to do any unit conversion...


floatSliderGrp -min 90 -max 145 -field true -width 30 L_Wrist_T;

Now to make the bone rotation follow the value of slider as you move it, you have to add a `-dc` flag which executes a command every time you move a slider. Now you make procedure.


floatSliderGrp -min 90 -max 145 -field true -width 30 -dc "procName" L_Wrist_T;

now make a procedure :

proc procName()

float $sliderValue = `floatSliderGrp -q -v L_Wrist_T`; //this puts the slider value in a variable
setAttr ("bone.ry" , $sliderValue); // change the bone rotation attribute to this value

-dc flag executes this procedure every time you move a slider. Everything should work now. I'm not if setAttr line has correct syntax, but I hope you get the idea...


10 October 2003, 05:25 PM
What you're asking for is really easy if you were willing to expose the actual angles (rather than your rescaled 0-10 values) to the user. The connectControl command will let you directly connect a control to an attribute.

string $mySphere[] = `sphere`;

string $group_name = `floatSliderGrp -label rotX -min 0 -max 30`;
connectControl $group_name ($mySphere[0] + ".rx");

Now, if you REALLY don't want to expose those angles to the user, you could make a custom attribute and an expression to do the conversion:

string $mySphere[] = `sphere`;

addAttr -shortName rc -longName rot_control;

string $myExpression = ($mySphere[0] + ".rx = (" + $mySphere[0] + ".rc * 5.5) + 90.0;");
print ("Adding expression " + $myExpression + "\n");
expression -s $myExpression;

string $group_name = `floatSliderGrp -label rotX -min 0 -max 10`;
connectControl $group_name ($mySphere[0] + ".rc");

In this example I'm building an expression in a string that hooks the new rc attribute to rx, doing the multiply and add to get 0 to map to 90 and 10 to map to 145. You can see the expression printed out when you run the code.

BTW, you should stop by the forums at sometime. It's a different group of people and you might get a wider picture if you post your question both here and there.

-- Mark

10 October 2003, 05:27 PM
Incidentally, the secret trick with connectControl is that it's easy to use in a loop where you grab a bunch of attributes from an object and make controls for all of them on the fly.

-- Mark

10 October 2003, 10:21 AM
thanks master Wilkins!

I was looking for a two way connection UI for quite some time.
And connectControl is the magic word. Now my facial animation UI can finally be finished...

equinox - listen to the man... and forget my stuff :)



That is a truly great and inspiring book about MEL scripting you have out there.

10 October 2003, 04:53 PM
Thank you so much. This is great code :) But I don't know how can I connect this code with my existence bone(s). :buttrock:

CGTalk Moderation
01 January 2006, 10:00 AM
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.