/*
This JScript example illustrates how to use the resample method to
add keys to an fcurve and the getkeyindex() method to look up an
keys index from a frame value.
*/
// 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()
// Start editing the fcurve
fc.BeginEdit();
// Use the Resample method to add keys to the fcurve on every second frame
var empty;
fc.Resample(empty,empty,2);
// Look up the key near frame 25
var key, index, frame, tolerance, keyframe;
frame = 24;
tolerance = 1;
if ( fc.KeyExists( frame, tolerance ) )
{
// Get index from frame using a tolerance of 1 frame (for example, 25 +/- 1 frame).
// This will find the key at frame 23
index = fc.GetKeyIndex( frame, tolerance );
keyframe = fc.GetKeyFrame( index );
LogMessage( "found key " + index + " at frame " + keyframe + " between frame "
+ (frame-tolerance) + " and " + (frame+tolerance) );
// Get the key at index
key = fc.GetKeyAtIndex( index );
// Set the key value
key.Value = Math.random() * 100;
}
// End editing the fcurve and put the undo event onto
// the undo/redo stack
fc.EndEdit();
// Outputs:
//INFO : found key 11 at frame 23.000000000000003 between frame 23 and 25
|