Mirroring MotionBuilder Character Animation with Python

In a previous post I went over “Plotting and Plot Options” as well as “dir” where we exposed the “MirrorMode” of a Character.

Now with all that information exposed I will show you how I created a simple script that will mirror a Character’s animation, first by setting the “MirrorMode” to be enabled, then we will plot the animation and finally the “MirrorMode” will be set off.

from pyfbsdk import *

# Creat lCharacter
lCharacter = FBApplication().CurrentCharacter

#Plot Ctrl Setttings
PlotCtrlRigTakeOptions = FBPlotOptions()
PlotCtrlRigTakeOptions.ConstantKeyReducerKeepOneKey = False
PlotCtrlRigTakeOptions.PlotAllTakes = False
PlotCtrlRigTakeOptions.PlotOnFrame = True
PlotCtrlRigTakeOptions.PlotPeriod = FBTime( 0, 0, 0, 1 )
PlotCtrlRigTakeOptions.PlotTranslationOnRootOnly = False
PlotCtrlRigTakeOptions.PreciseTimeDiscontinuities = False
PlotCtrlRigTakeOptions.RotationFilterToApply = FBRotationFilter.kFBRotationFilterUnroll
PlotCtrlRigTakeOptions.UseConstantKeyReducer = False

if lCharacter.MirrorMode == False:
    # Turn on Mirror
    lCharacter.MirrorMode = True
    # Plot On Skeleton
    lCharacter.PlotAnimation (FBCharacterPlotWhere.kFBCharacterPlotOnSkeleton,PlotCtrlRigTakeOptions )
    # Plot Back On Control Rig
    lCharacter.PlotAnimation (FBCharacterPlotWhere.kFBCharacterPlotOnControlRig,PlotCtrlRigTakeOptions )
    # Turn Off Mirror
    lCharacter.MirrorMode = False

else:
    # Plot On Skeleton
    lCharacter.PlotAnimation (FBCharacterPlotWhere.kFBCharacterPlotOnSkeleton,PlotCtrlRigTakeOptions )
    # Plot Back On Control Rig
    lCharacter.PlotAnimation (FBCharacterPlotWhere.kFBCharacterPlotOnControlRig,PlotCtrlRigTakeOptions )
    # Turn Off Mirror
    lCharacter.MirrorMode = False

# Clean up
del (lCharacter)

In production I created a similar script for my team except it had worked like this:
1. Create a Copy of the Current take
2. Name the New take to “the original takes name” + “_Mirrored”
3. On the New take (“the original takes name” + “_Mirrored”) set the “MirrorMode” to be on
4. Set up my Plotting Options and Plot to Skeleton and then back to Ctrl rig (just like we did with the above script)
5. Turn Mirror Mode off

This type of script is great to not only make mirroring animation faster but also to ensure that turning “MirrorMode” off is never forgotten – I did that a lot.

I hope this helps.

6 Comments

Add a Comment

Your email address will not be published. Required fields are marked *