Ben Traje
← Back to maya

Set Driven Key Maya MEL Expression Equivalent

04 Feb 26 (16d ago)

Normally, when you just want a simple if/else driven-driver relationship, rather than building a node setup, you can just pop Key>Set Drive Key. And it is robust. Not only it works even after you rename your object, you can also set a curve profile on how the figures interpolate.

But, in this case, I always just prefer using the MEL expression alternative through the Windows>Animation Editors>Expresion Editor. It lacks the features mentioned above but it allows me to easily iterate on what values work to interpolate.

A quick example would be a simple slider for trigger both eye blinks. Different eye shapes requires different values.

P.S. Like the traditional SDK, this does not replace Radial Basis Function (RBF) set ups.

// Hip_L is the driver in this case
// while FKExtraFrontFlap01_M is the driven

// Define the input attributes
float $input_L = Hip_L.rotateZ;

// Define the input range
float $inputMin = 0.0;
float $inputMax = 60.0;

// Define the output range
float $outputMin = 0.0;
float $outputMax = 50.0;

// Calculate the normalized value for Hip_L (0 to 1)
float $normalizedValue_L = ($input_L - $inputMin) / ($inputMax - $inputMin);
$normalizedValue_L = clamp($normalizedValue_L, 0.0, 1.0); // Ensure the value is within range

// Map the normalized value for Hip_L to the output range
float $mappedValue_L = $outputMin + ($normalizedValue_L * ($outputMax - $outputMin));

FKExtraFrontFlap01_M.rotateZ = $mappedValue_L;