NextKey

Description

Moves current frame to the next key frame for the given animation parameters. If InputObjs argument is left blank (skipped), current selected and marked parameters are used.

This is the scripting equivalent of selecting Next Key from the animation pop-up menu (or pressing Ctrl+Right with the default keyboard layout).

Scripting Syntax

NextKey( [InputObjs], [Time], [Tolerance], [Layer] )

Parameters

Parameter

Type

Description

InputObjs

String

List of animatable parameters (for example "cone*/kine.local.pos").

Default Value: Currently selected and marked parameters

Time

Number

Move to the next key after this frame.

Default Value: Current frame

Tolerance

Double

Frame tolerance

Default Value: Nearest 0.5 frame (-1)

Possible Values:

>0: Get key at Frame + Tolerance

0: Key must be exactly at frame

-1: Nearest 0.5 frame

Layer

Integer

Animation layer

Default Value: Current animation layer (-1)

Return Value

Returns the frame number of the next key frame as a Double. If there is no key then the following is returned:

"1.#INF" for C++, "1.#INF" for VBScript

"Number.POSITIVE_INFINITY" for JScript.

Examples

VBScript Example

'
' This example sets up some animation on the X position of a sphere, moves to the next key frame,
' prints out the key information for this parameter, removes the next key and prints out the 
' key information again.
'
' Set up an object to animate
set oGlobe = CreatePrim( "Sphere", "NurbsSurface", "MySphere" )

' Set the maximum frame number to 40
SetValue "PlayControl.Out", 40

' Set some keys on XPos at various frames
SaveKey oGlobe & ".kine.local.posx", 1, -9.0
SaveKey oGlobe & ".kine.local.posx", 10, 3.0
SaveKey oGlobe & ".kine.local.posx", 30,-3.0
SaveKey oGlobe & ".kine.local.posx", 40, 9.0

' Return to frame 1
SetValue "PlayControl.Current", 1

' Goto key at frame 10
NextKey oGlobe & "/kine.local.pos"

' Print out key info for the globe's position in X before
' removing the next key
WhereAmI oGlobe

' Remove key at frame 30 (next key)
if RemoveNextKey( oGlobe & "/kine.local.pos" ) then
   LogMessage "Successfully removed the key."
else
   LogMessage "This is the last key."
end if

' Print out key info for the globe's position in X after
' removing the next key
WhereAmI oGlobe

' Goto NextKey (at frame 40 now)
NextKey ( oGlobe & "/kine.local.pos" )



' This function removes the next key (provided that there is a next key to remove)
' and returns a Boolean value indicating whether it could remove the key or not.
function RemoveNextKey ( in_parameter )
   ' Check if there is another key (if there is no next key, NextKey returns "1.#INF")
   if ( NextKey( in_parameter ) <> "1.#INF" ) then
       RemoveKey in_parameter
       RemoveNextKey = true
       exit function
   end if

   RemoveNextKey = false
end function 



' This subroutine prints out the total number of keys on the object, and then prints
' the frame number and value for each key in the collection.
sub WhereAmI( in_object )
   if TypeName( in_object ) <> "Nothing" then
       ' Get the fcurve object that is attached to the XPos parameter
       set oAnimationFC = in_object.posx.Source

       ' From the fcurve object you can get the list of keys
       set oFCKeys = oAnimationFC.Keys

       ' Make sure there are some keys on the parameter
       if oFCKeys.Count > 0 then
          ' Print the total number of keys now present on this parameter
          LogMessage "Number of keys on the " & in_object & " object: " & oFCKeys.Count

          ' Loop through the collection of keys, printing out the key index & its frame number
          for each k in oFCKeys
              LogMessage "Key [" & k.Index & "] is set on Frame[" & k.Time & "] with a value of " & k.Value 
          next
       end if
   end if
end sub




' Output of above script:
'...before key was removed
'INFO : "Number of keys on the MySphere object: 4"
'INFO : "Key [0] is set on Frame[1] with a value of -9"
'INFO : "Key [1] is set on Frame[10] with a value of 3"
'INFO : "Key [2] is set on Frame[30] with a value of -3"
'INFO : "Key [3] is set on Frame[40] with a value of 9"
'
'INFO : "Successfully removed the key."
'
'...after key was removed
'INFO : "Number of keys on the MySphere object: 3"
'INFO : "Key [0] is set on Frame[1] with a value of -9"
'INFO : "Key [1] is set on Frame[10] with a value of 3"
'INFO : "Key [2] is set on Frame[40] with a value of 9"

See Also

AddFCurve

RemoveAnimation

RemoveAllAnimation

SaveKey

RemoveKey

PrevKey

FirstKey

LastKey

FCurve.Keys

 

 

 



Autodesk Softimage v7.5