from pyfbsdk import *
import time
def SwitchTake ( pTakeName ):
iDestName= pTakeName
for iTake in lSystem.Scene.Takes:
if iTake.Name == iDestName:
lSystem.CurrentTake = iTake
lApplication = FBApplication()
lCharacter = lApplication.CurrentCharacter
lSystem = FBSystem()
lOriginalTake = lSystem.CurrentTake.Name
lPlayer = FBPlayerControl()
lEndTime = lSystem.CurrentTake.LocalTimeSpan.GetStop()
lEndFrame = lSystem.CurrentTake.LocalTimeSpan.GetStop().GetFrame(True)
lStartFrameTime = lSystem.CurrentTake.LocalTimeSpan.GetStart()
lStartFrame = lSystem.CurrentTake.LocalTimeSpan.GetStart().GetFrame(True)
lAnimPoseTake = lOriginalTake + ' mirror ' + str( lSystem.SystemTime.GetTimeString() )
lNewTake = FBTake(lAnimPoseTake)
lNewTake = lNewTake.CopyTake(lAnimPoseTake)
poseOptions = FBCharacterPoseOptions()
poseOptions.mCharacterPoseKeyingMode = FBCharacterPoseKeyingMode.kFBCharacterPoseKeyingModeFullBody
poseOptions.SetFlag(FBCharacterPoseFlag.kFBCharacterPoseMirror, True)
lCharacter.KeyingMode=FBCharacterKeyingMode.kFBCharacterKeyingFullBody
lScene = lSystem.Scene
lStop = int(lEndFrame)
lRange = int(lEndFrame)+1
lTime = lStartFrameTime
lStart = int(lStartFrame)
lProgress = lRange - lStart
FBKeyControl().AutoKey = True
lFbp = FBProgress()
lFbp.Caption = "Mirroring "
lFbp.Text = "over time ..."
lCount = 0.0
for i in range(lRange):
timeout = False
lPlayer.Goto(lTime)
while not lPlayer.Goto(lTime)or timeout:
time.sleep(1)
lSystem.Scene.Evaluate()
if timeout>5:
print "Unable to Go to time "+lTime.GetTimeString()
break
timeout+=1
poseName = 'CharacterPose_'+str(i)
targetPose = FBCharacterPose(poseName)
lSystem.Scene.Evaluate()
targetPose.CopyPose(lCharacter)
SwitchTake(lAnimPoseTake)
lSystem.Scene.Evaluate()
targetPose.PastePose(lCharacter, poseOptions )
lSystem.Scene.Evaluate()
lPlayer.Key()
lSystem.Scene.Evaluate()
SwitchTake(lOriginalTake)
targetPose.FBDelete()
lTime.Set(lTime.Get() + FBTime(0,0,0,1).Get())
lCount += 1
lVal = lCount / lProgress * 100
lFbp.Percent = int(lVal)
lFbp.FBDelete()
SwitchTake(lAnimPoseTake)
lSetTimeSpan = FBTimeSpan(FBTime(0,0,0,lStart),FBTime(0,0,0,lStop) )
lSystem.CurrentTake.LocalTimeSpan = lSetTimeSpan
FBKeyControl().AutoKey = False
lPlayer.GotoStart()
print 'done'