Search code examples
3d3dsmaxmaxscript

Deleting #allKeys but first 2 in 3DS Max 2010 with MAXScript


I have been using this simple MAXScript to clear an animation on 3DS Max 2010:

deleteKeys objects #allKeys

Is there a simple way like this to delete all the keyframes but keeping the first 2?


Solution

  • --Select objects in viewport , run script.
    -- it keeps the 2 first keyframes for each controller and removes the rest.
    
    for o in selection do
    (
        if (o.position.controller.keys.count > 2) do
        (
            for i = 1 to (o.position.controller.keys.count - 2) do
            (
                deleteitem o.position.controller.keys (i + 2)
            )
        )   
        if (o.rotation.controller.keys.count > 2) do
        (
            temp = (o.rotation.controller.keys.count - 2)
            for i = 1 to temp do
            (
                deleteitem o.rotation.controller.keys (i + 2)
            )
        )   
        if (o.scale.controller.keys.count > 2) do
        (
            temp = (o.scale.controller.keys.count - 2)
            for i = 1 to temp do
            (
                deleteitem o.scale.controller.keys (i + 2)
            )
        )   
    )