FCurve.GetNumKeys
 
 
 

FCurve.GetNumKeys

Introduced

v3.0

Description

Returns the number of keys within the interval defined by the StartFrame and EndFrame. The default interval is the entire fcurve.

C# Syntax

Int32 FCurve.GetNumKeys( Object in_StartFrame, Object in_EndFrame );

Scripting Syntax

oLong = FCurve.GetNumKeys( [StartFrame], [EndFrame] );

Return Value

Long

Parameters

Parameter Type Description
StartFrame Variant The start time in frames of the interval.

Default Value: The frame of the first key

EndFrame Variant The end time in frames of the interval.

Default Value: The frame of the last key

Examples

JScript Example

/*
        This JScript example illustrates how to use the FCurve.GetNumKeys method
        to determine the number of keys within a specified interval.
*/
// 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()
// Define some random keys
var nbkeys = Math.round( Math.random() * 200 );
var arraysize = nbkeys * 2;
var keys = new Array( 2 * nbkeys );
var i = 0;
var offset = -50;
for ( i=0; i<arraysize; i+=2 )
{
        keys[i] = Math.round( offset + Math.random( ) * 100 );
        keys[i+1] = offset + Math.random() * 100;
}
// Set the keys on the fcurve
fc.SetKeys( keys );
LogMessage( "total number of keys = " + fc.GetNumKeys() );
// For each 10 frames determine how many keys are in the interval
var frame, nextframe, endframe, offset;
frame = fc.GetKeyFrame(0);
endframe = fc.GetKeyFrame( fc.GetNumKeys() - 1 );
offset = 10;
while ( frame < endframe )
{
        nextframe = frame + offset;
        var ckeys = fc.GetNumKeys( frame, nextframe );
        if ( ckeys > 1 )
        {
                LogMessage( ckeys + " keys between frames " + frame + " and " + nextframe );
        }
        frame = nextframe;
}
// Output:
//INFO : total number of keys = 78
//INFO : 10 keys between frames -50 and -40
//INFO : 6 keys between frames -40 and -30
//INFO : 9 keys between frames -30 and -20
//INFO : 6 keys between frames -20 and -10
//INFO : 9 keys between frames -10 and 0
//INFO : 10 keys between frames 0 and 10
//INFO : 9 keys between frames 10 and 20
//INFO : 7 keys between frames 20 and 30
//INFO : 11 keys between frames 30 and 40
//INFO : 8 keys between frames 40 and 50

See Also

FCurve.Keys