Tasks/FBKeyingGroupLocal.py

Tasks/FBKeyingGroupLocal.py
1 # Copyright 2010 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 ########################################
7 # By: Kristine Middlemiss, ADN, 2010
8 ########################################
9 
10 # Script description:
11 # Create Custom 'Local' Keying Group.
12 # This script creates a cube and adds translation, rotation and scaling properties of the
13 # cube into a custom keying group, when you key the cube all three properties are Keyed,
14 # (the default keying of a cube is only translation and rotation). In addition, after those
15 # three properties are keyed on the cube, we remove the translation property for our custom
16 # keying group, and test with keying that only the two remaining properties are set. Briefly
17 # showes you how to remove all properties from you custom property group and deleting the
18 # your custom key group.
19 
20 #Topic: FBKeyingGroup, FBKeyingGroupType, FBKeyingGroup.AddProperty, FBKeyingGroup.SetActive, FBKeyingGroup.SetEnabled, FBKeyingGroup.GetPropertyCount, FBKeyingGroup.FindPropertyIndex, FBKeyingGroup.GetCumulativePropertyCount, FBKeyingGroup.RemoveProperty, FBKeyingGroup.RemoveAllProperties, FBKeyingGroup.FBDelete
21 
22 from pyfbsdk import *
23 
24 ## Scene Setup ##
25 # Get to the handle to the model
26 lCube = FBModelCube("Cube")
27 lCube.Translation.SetAnimated(True)
28 lCube.Rotation.SetAnimated(True)
29 lCube.Scaling.SetAnimated(True)
30 lCube.Show = True
31 
32 # Use the screen name to set the translation vector
33 ltran = lCube.PropertyList.Find ( 'Translation (Lcl)' )#.Data = FBVector3d( -10, 5, 20 )
34 lrot = lCube.PropertyList.Find ( 'Rotation (Lcl)' )
35 lsca = lCube.PropertyList.Find ( 'Scaling (Lcl)' )
36 
37 #Create Local Custom Key Group
38 localKeyGroup = FBKeyingGroup("KrisLocalKeyGroup", FBKeyingGroupType.kFBKeyingGroupLocal)
39 
40 #Get Property Count
41 print "Property Count Before Added Properties: %d \n" % localKeyGroup.GetPropertyCount ()
42 
43 #Add Properties to Custom Key Group
44 localKeyGroup.AddProperty(ltran)
45 localKeyGroup.AddProperty(lrot)
46 localKeyGroup.AddProperty(lsca)
47 
48 #Get Property Count
49 print "Property Count After Added Properties: %d \n"% localKeyGroup.GetPropertyCount ()
50 
51 # SetActive, activate the keying group.
52 localKeyGroup.SetActive (True)
53 
54 # SetEnabled, will make available the keying group in keying group list of the key control UI.
55 localKeyGroup.SetEnabled (True)
56 
57 #Getting the CumulativePropertyCount
58 print localKeyGroup.GetCumulativePropertyCount ()
59 
60 #Testing New Custom Keying Group, to make sure it included Scale
61 lPlayer = FBPlayerControl()
62 ltran.Data = FBVector3d( 0, 0, 0 )
63 lrot.Data = FBVector3d( 0, 45, 0 )
64 lsca.Data = FBVector3d( 5, 5, 5 )
65 lPlayer.Key()
66 
67 lPlayer.Goto(FBTime(0,0,0,20))
68 ltran.Data = FBVector3d( -80, 0, 00 )
69 lrot.Data = FBVector3d( 0, 45, 0 )
70 lsca.Data = FBVector3d( 1, 1, 1 )
71 lPlayer.Key()
72 
73 # Remove Translation Property From the Key Group
74 localKeyGroup.RemoveProperty (ltran)
75 
76 # Test that it does not Key the Translation
77 lPlayer.Goto(FBTime(0,0,0,40))
78 ltran.Data = FBVector3d( 80, 0, 00 )
79 lrot.Data = FBVector3d( 0,0, 0 )
80 lsca.Data = FBVector3d( 5, 5, 5 )
81 lPlayer.Key()
82 
83 #Working with additional Functions:
84 # Any property not in our custom keying group returns a value of -1, you can test with ltran
85 # The properties index changes when items are added and removed, not hard coded.
86 print "FindPropertyIndex", localKeyGroup.FindPropertyIndex (lrot)
87 print "FindPropertyIndex", localKeyGroup.FindPropertyIndex (lsca)
88 
89 # GetCumulativePropertyCount Same as GetSubKeyingGroupCount but recursive in child keying group.
90 print localKeyGroup.GetCumulativePropertyCount ()
91 
92 #Empty KeyGroup, commented out so you can verify the above works.
93 #localKeyGroup.RemoveAllProperties ()
94 
95 #Delete the KeyGroup, commented out so you can verify the above works.
96 #localKeyGroup.FBDelete()