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.
script not working 🙁
SyntaxError: invalid syntax in line 17
Sorry John.
WordPress ignored the indents when i did a copy and paste.
The error you would of received would of been “IndentationError: expected an indented block”.
It is fixed now, there was a typo in my wordpress posting
(code language=python) should of been [code language=python]
I hope this helps.
Hello Victor,
Is there a way to set also mirror plane via python? I have been searching for this quite long and have not found anything. This script works pretty fine for X-Y plane, but I am wondering, if there is possible to do it also for Z-Y plane.
Thanks for any advise.
Hi Burk, thanks for reaching out AND for giving me a great topic for a new post. 🙂
You can find out how to mirror and animation along a plane here:
motionbuilder-python-mirror-character-animation-through-story-mode/
Hi Victor,
Thank you very much for your answer and new post, I am looking forward to test it!
Have a great day and thanks for your excellent blog, it is very inspiring.
Sincerely, Burk
No worries.