Samples/FCurve/CopyAnimation.py

# 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, FBFindModelByName
#

from pyfbsdk import *

# Find the animation node recurvesive by name.
def findAnimationNode( pName, pNode ): 
    lResult = None 
    lName = pName.split( '/' ) 
    for lNode in pNode.Nodes: 
        if lNode.Name == lName[0]: 
            if len( lName ) > 1: 
                lResult = findAnimationNode( pName.replace( '%s/' % lName[0], '' ), lNode ) 
            else: 
                lResult = lNode 
    return lResult 

# Copy Model's TR animation data  
def copyAnimation(pSrc, pDst ): 
    for pName in [ 'Lcl Translation/X','Lcl Translation/Y','Lcl Translation/Z', 'Lcl Rotation/X','Lcl Rotation/Y','Lcl Rotation/Z']: 
        lSrcNode = findAnimationNode( pName, pSrc.AnimationNode ) 
        lDstNode = findAnimationNode( pName, pDst.AnimationNode )           

        if lSrcNode and lSrcNode.FCurve and lDstNode: 
            lDstNode.FCurve.KeyReplaceBy(lSrcNode.FCurve)

lSrc = FBFindModelByName( 'SRC' ) 
lDst = FBFindModelByName( 'DST' )

## Ensure that TRS properties are animated
if lSrc:
    lSrc.Translation.SetAnimated(True)
    lSrc.Rotation.SetAnimated(True)
    lSrc.Scaling.SetAnimated(True)
if lDst:
    lDst.Translation.SetAnimated(True)
    lDst.Rotation.SetAnimated(True)
    lDst.Scaling.SetAnimated(True)

if lSrc and lDst:
    copyAnimation(lSrc, lDst)