RemoveKey
 
 
 

RemoveKey

Description

Removes key frames from parameters at a given frame. This is the scripting equivalent of selecting Remove Key from the animation pop-up menu (or pressing Shift+K with the default keyboard layout).

Note: If any of the keys cannot be removed the command raises an siErrCancelled error; see siErrorValueEnum for details. To avoid an error wrap the call to RemoveKey with the 'On Error Resume Next...On Error Goto 0' statements in VBScript or the 'try()...catch(e)' construction in JScript.

Scripting Syntax

RemoveKey( [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 Key frames are removed at this frame.

Default Value: Current frame

Tolerance Double Frame tolerance

Default Value: Nearest 0.5 frame (-1)

Possible Values:

Description:

> 0 Remove all keys between ( keyframe - tolerance and keyframe + tolerance )
0 Key must be exactly at frame
-1 Nearest 0.5 frame
Layer Integer Animation layer to remove keys from

Default Value: Current animation layer (-1)

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

RemoveKeyOnKeyable RemoveKeyOnMarkedKeyable AddFCurve RemoveAnimation RemoveAllAnimation SaveKey PrevKey NextKey FirstKey LastKey FCurve.RemoveKey