Python Reference Guide
 
Loading...
Searching...
No Matches
Samples\FCurve\CopyAnimation.py
1# Copyright 2009 Autodesk, Inc. All rights reserved.
2# Use of this software is subject to the terms of the Autodesk license agreement
3# provided at the time of installation or download, or which otherwise accompanies
4# this software in either electronic or hard copy form.
5#
6# Topic: FBAnimationNode, FBFindModelByLabelName
7#
8
9from pyfbsdk import *
10
11# Find the animation node recurvesive by name.
12def findAnimationNode( pName, pNode ):
13 lResult = None
14 lName = pName.split( '/' )
15 for lNode in pNode.Nodes:
16 if lNode.Name == lName[0]:
17 if len( lName ) > 1:
18 lResult = findAnimationNode( pName.replace( '%s/' % lName[0], '' ), lNode )
19 else:
20 lResult = lNode
21 return lResult
22
23# Copy Model's TR animation data
24def copyAnimation(pSrc, pDst ):
25 for pName in [ 'Lcl Translation/X','Lcl Translation/Y','Lcl Translation/Z', 'Lcl Rotation/X','Lcl Rotation/Y','Lcl Rotation/Z']:
26 lSrcNode = findAnimationNode( pName, pSrc.AnimationNode )
27 lDstNode = findAnimationNode( pName, pDst.AnimationNode )
28
29 if lSrcNode and lSrcNode.FCurve and lDstNode:
30 lDstNode.FCurve.KeyReplaceBy(lSrcNode.FCurve)
31
32lSrc = FBFindModelByLabelName( 'SRC' )
33lDst = FBFindModelByLabelName( 'DST' )
34
35
36if lSrc:
37 lSrc.Translation.SetAnimated(True)
38 lSrc.Rotation.SetAnimated(True)
39 lSrc.Scaling.SetAnimated(True)
40if lDst:
41 lDst.Translation.SetAnimated(True)
42 lDst.Rotation.SetAnimated(True)
43 lDst.Scaling.SetAnimated(True)
44
45if lSrc and lDst:
46 copyAnimation(lSrc, lDst)
FBModel FBFindModelByLabelName(str pModelLabelName)
Find a model in the scene by its label name.