FCurveKey.Set

Introduced

v3.0

Description

Sets the fcurvekey time (see FCurveKey.Time) and value (see FCurveKey.Value).

Note: If another key already exists at the new frame value then the method raises a 'Cannot set key' (E_FAIL) error.

Tip: If the fcurve if locked then the method raises an 'Access Denied' (E_ACCESSDENIED) error. See FCurveKey.Constraint property for examples using error trapping to catch this error.

Scripting Syntax

FCurveKey.Set( Frame, Value, [OverrideKeyLock] );

Parameters

Parameter Type Description
Frame Variant The new key time in frames.
Value Variant The new key value.

For standard and raw fcurves use a double value (VT_R8)

For integer fcurves use a LONG (VT_I4)

For boolean fcurves use a variant bool value (VT_BOOL,VARIANT_TRUE,VARIANT_FALSE).
OverrideKeyLock Boolean True to override the FCurveKey.Locked value to force key to be removed.

Default Value: false

Examples

JScript Example

/*
        This example illustrates how to use the FCurveKey.Set method to translate keys.
*/
// Create new scene
Application.NewScene( "", false );
var empty;
var nullobj = Application.ActiveSceneRoot.AddNull();
var cpset = nullobj.AddProperty( "Custom_parameter_list", empty, "CustomPSet" );
var x = cpset.AddParameter( "X", siDouble, empty, siAnimatable, "X", "X", empty, 0.25, -100, 100 );
var y = cpset.AddParameter( "Y", siDouble, empty, siAnimatable, "Y", "Y", empty, 0.25, -100, 100 );
// Create some fcurves
var fc1 = x.AddFCurve();
var fc2 = y.AddFCurve();
// Start editing fcurve
fc1.BeginEdit();
fc2.BeginEdit();
// Add keys to the fcurves
fc1.Resample();
fc2.Resample();
// Assign some values to keys
for ( i=0; i<fc1.GetNumKeys(); i++ ) {
        var calcX = ((i+1)-10)/10;
        fc1.GetKeyAtIndex(i).Value = Math.atan(calcX / Sqr(-calcX * calcX + 1));
        // Copy the value to fc2 for comparison
        fc2.GetKeyAtIndex(i).Value = fc1.GetKeyValue(i);
}
var ckeys = fc1.GetNumKeys();
var tangents = new Array(ckeys*4);
var itan=0;
// Save tangents
for ( var i=0; i<ckeys; i++ ) {
        var fckey = fc1.GetKeyAtIndex(i);
        // Save the tangents
        tangents[itan++] = fckey.LeftTanX;
        tangents[itan++] = fckey.LeftTanY;
        tangents[itan++] = fckey.RightTanX;
        tangents[itan++] = fckey.RightTanY;
}
// Translate the keys
for ( var i=0; i<ckeys; i++ ) {
        var frame = fc1.GetKeyFrame(i);
        var val = fc1.GetKeyValue(i);
        var fckey = fc1.GetKey(frame);
        fckey .set( frame-100, val * 1.25 );
}
// Reset the tangents
fc1.SetKeyTangents(tangents);
// End editing fcurve
fc2.EndEdit();
fc1.EndEdit();
// Convenience function
function Sqr( x ) 
{
        return x * x;
}