Using sliders to control expressions

Using sliders to control expressions

samunawa
Enthusiast Enthusiast
686 Views
1 Reply
Message 1 of 2

Using sliders to control expressions

samunawa
Enthusiast
Enthusiast

Hi there. I've been trying for a while to find out how one would go about controlling expressions using a sliders (intslider/floatslider).

 

What I'm trying to do is I'm trying to create a slider for a car I'm rigging using MEL and expressions. So far I've managed to do something very basic after a lot of struggle. Heres my expression code:

body.translateZ = time*2;
body|back_left.rotateX = body.translateZ*125;
body|back_right.rotateX = body.translateZ*125;
body|front_right.rotateX = body.translateZ*125;
body|front_left.rotateX = body.translateZ*125

What I need is a slider that controls the value of the "2" on the first line. So say for example, creating a intslider with a min/max value of 0 and 10 would mean that as the slider changes from lets say value 4 to 5, it would also do the same as well on the expression.

 

And as for the wheels, the body essentially drives the wheels since the wheels are a child of the body as shown in the code above. I would appriciate any input :), thanks.

 

 

0 Likes
687 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

That's not difficult. There are several ways you could create a slider, but the following code creates a new window for example. You can create the window by calling ShowWindow(). The window creates a new slider and the slider has a change command. The method will be called when the values of the slider changes. Inside the method we read the value and for example set the translation x value of an object.

 

global proc SliderValueChanged()
{
   float $value = `floatSliderGrp -q -value gMySlider`;
   
   // Use the name of the object, or for example all selected objects, ...
   // Currently simply use a hard-coded name for a created sphere
   string $objectName = "pSphere1";
   
   setAttr ($objectName + ".translateX") $value;
}

global proc ShowWindow()
{
    string $sWindow = `window -title "TestWindow" -widthHeight 400 128`;
    
    floatSliderGrp -label "Slider" -minValue 0 -maxValue 10 -changeCommand "SliderValueChanged()" gMySlider;
    
    showWindow $sWindow;
}

ShowWindow();

 So just copy this code to your mel script editor and execute it. a new window should open containing the slider. 

0 Likes