Running A Python Script On All Takes. 

Being able to run a Python script on all takes within a MotionBuilder scene is a powerful time saver.

Below I’m going to show how I learned to create a layer on every take within a MotionBuilder scene using Python.

We are going to use Python to create an Animation Layer on all takes within our scene:

from pyfbsdk import *

#Define lSystem
lSystem = FBSystem()

# On all Takes within the Scence
for take in FBSystem().Scene.Takes:
#Create a new layer
lSystem.CurrentTake.CreateNewLayer()
#Find how many layers are now in the take
lCount = lSystem.CurrentTake.GetLayerCount()

#set the new layer (the top layer)as the current one (Keys will be added to that layer)
lSystem.CurrentTake.SetCurrentLayer(lCount-1)

The above code works, however there is an issue with how user friendly it is. We are always one the last take in our scene once the script is finished – LET’S FIX IT ! 🙂

Using pyfbsdk to create layers is great but the fun is merging all layers on all takes through a Python script. I run a script similar to the one below when I am doing my final clean up within my MotionBuilder scene. Once the script has finished running you will be positioned back onto the take in which you were on before you executed the script – this is great if you are dealing with a lot of takes.

A word of warning – depending on the size of your scene (the amount and length of the takes, the amount of layers, number of objects, etc.) running a script on every take can take time to complete (good time to grab a coffee). If your scene is complex and large then please save first before running a batch script.

from pyfbsdk import *

#Define lSystem
lSystem = FBSystem()

# Store what take you are on before the script was run
lOriginalTake = lSystem.CurrentTake
print lOriginalTake.Name + " was the take you were on" #some fun to remind you of where you were

# On all Takes within the Scence
for take in FBSystem().Scene.Takes:
#Merge all object in the scene to the BaseAnimation layer and delete the empty layers
FBSystem().CurrentTake.MergeLayers(FBAnimationLayerMergeOptions.kFBAnimLayerMerge_AllLayers_CompleteScene, True, FBMergeLayerMode.kFBMergeLayerModeAutomatic)

# Return to the original take you were on before the script was run
lSystem.CurrentTake = lOriginalTake
#some fun to let you know where you are
print lSystem.CurrentTake.Name + " is the take you we brought you back to"

Storing lSystem.CurrentTake as lOriginalTake helps us return to the take we were on before running the script.

 

I hope this helps.

2 Comments

Leave a Reply to admin Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.