v3.0
Sets the time (in frames) and value of the key at the specified index.
Note: If another key already exists at the new frame value then the
method raises a 'Cannot set key' (E_FAIL) error.
If the index is out of range then the method raises an 'Invalid argument'
(E_INVALIDARG) error.
If the fcurve is locked then the method raises an 'Access Denied'
(E_ACCESSDENIED) error.
FCurve.SetKey( Int32 in_Index, Object in_Frame, Object in_Value, Boolean in_OverrideKeyLock ); |
FCurve.SetKey( Index, Frame, Value, [OverrideKeyLock] ); |
| Parameter | Type | Description |
|---|---|---|
| Index | Long | Index of the key. Must be a value between 0 and (number of keys - 1). |
| Frame | Variant | The new key time in frames. |
| Value | Variant |
The new key value. Use a value type as follows: 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 |
Override the FCurveKey.Locked value to force key to be removed. Default Value: false |
/*
This JScript example illustrates how to use the FCurve.SetKey method
to translate keys.
*/
// Create a null
Application.NewScene( null, false );
var nullobj = ActiveSceneRoot.AddNull();
// Create an fcurve on the posx parameter from the null
var fc = nullobj.posx.AddFCurve()
// Create a custom property set on the null
var cpset = nullobj.AddCustomProperty( "CustomPSet" );
var empty;
var x = cpset.AddParameter( "X", siDouble, empty, siAnimatable, "X", "X", empty, 5, 0, 5 );
var y = cpset.AddParameter( "Y", siInt4, empty, siAnimatable, "Y", "Y", empty, 5, 0, 5 );
var fc1 = x.AddFCurve();
var fc2 = y.AddFCurve();
// Start editing the fcurves
fc1.BeginEdit();
fc2.BeginEdit();
// Add keys to the fcurves
fc1.Resample();
fc2.Resample();
// Assign some values to keys
var val, X;
for ( i=0; i<fc1.GetNumKeys(); i++ )
{
X = ( (i+1) - 10 )/10;
fc1.GetKeyAtIndex(i).Value = Math.atan( X / Sqr( -X * X + 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 ( i=0; i<ckeys; i++ )
{
var key = fc1.GetKeyAtIndex(i);
// Save the tangents
tangents[itan++] = key.LeftTanX;
tangents[itan++] = key.LeftTanY;
tangents[itan++] = key.RightTanX;
tangents[itan++] = key.RightTanY;
}
// Translate the keys
for ( i=0; i<ckeys; i++ )
{
frame = fc1.GetKeyFrame(i);
val = fc1.GetKeyValue(i);
key = fc1.GetKey(frame);
fc1.SetKey( i, frame-100, val * 1.25 );
}
// Reset the tangents
fc1.SetKeyTangents(tangents);
// End editing the fcurves
fc1.EndEdit();
fc2.EndEdit();
// Utility function
function Sqr( x )
{
return x * x;
} |