# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Topic: FBAnimationNode, FBFCurve
#


from pyfbsdk import FBModelList, FBGetSelectedModels

def ClearAnim( pNode ):

    # The FCurve property will not be null on a terminal node.
    # i.e. the 'Lcl Translation' node will not have any animation on it
    # directly... only the sub-nodes 'X', 'Y' or 'Z' may have animation.
    if pNode.FCurve:

        # Ah! there is a FCurve! Let's remove all the keys.
        pNode.FCurve.EditClear()
    else:
        # Then we are dealing with a parent node. Let's look at it
        # children nodes.
        for lNode in pNode.Nodes:
            # Recursively call ourselves to deal with sub-nodes.
            ClearAnim( lNode )

            # Cleanup
            del( lNode )


# Create an empty FBModelList object.
lModels = FBModelList()

# Obtain the list of selected models.
FBGetSelectedModels( lModels )

# Clear the animation for all the models selected.
for lModel in lModels:
    ClearAnim( lModel.AnimationNode )

    # Cleanup.
    del( lModel )

# Cleanup of local objects.
del( lModels, ClearAnim )

# Cleanup of imported modules.
del( FBModelList, FBGetSelectedModels )