Using Python to Create a layer on the Current Selected Take in MotionBuilder. 

In MotionBuilder using animation layers are great for edits, blending, additives and in general adding quality passes to your animations.

So below I’m going to demo how I learned to add layers using Python.

To create an Animation Layer on the Current Take script:

from pyfbsdk import *

lSystem = FBSystem()

##Create a new layer on the current take
lSystem.CurrentTake.CreateNewLayer()
# Get the Layer Count for the current take
lCount = lSystem.CurrentTake.GetLayerCount()
# Use the layer count to name the layer: "lCount-1" = top most layer, "lCount-2" = second top most layer, "lCount-3" = third from the top layer, etc.
lSystem.CurrentTake.GetLayer(lCount-1).Name= "Creat Through Python"
#Set the top most layer as the selected/active one (Keys will be added to that layer)
#if you have 5 Animation layers and want the second one from the top selected you would use "lCount-2"
lSystem.CurrentTake.SetCurrentLayer(lCount-1)

Now let’s setup a Python Script to Merge all Layers and then Delete Merged Layers:

from pyfbsdk import *

lSystem = FBSystem()

#Merge all object in the scene to the BaseAnimation layer, delete the source layers if they are empty    
FBSystem().CurrentTake.MergeLayers(FBAnimationLayerMergeOptions.kFBAnimLayerMerge_AllLayers_CompleteScene, True, FBMergeLayerMode.kFBMergeLayerModeAutomatic)

#Info - Merge option for animation layers:
# kFBAnimLayerMerge_SelectedLayers_SelectedProperties = Merge the animation of the selected properties of the selected models from the selected layers to the selected layer with the lowest index.
# kFBAnimLayerMerge_AllLayers_SelectedProperties = Merge the animation of the selected properties of the selected models from all the layers to the BaseAnimation layer.
# kFBAnimLayerMerge_SelectedLayers_AllProperties = Merge the animation of all properties of the selected models from the selected layers to the selected layer with the lowest index.
# kFBAnimLayerMerge_AllLayers_AllProperties = Merge the animation of all properties of the selected models from all the layers to the BaseAnimation layer.
# kFBAnimLayerMerge_SelectedLayers_CompleteScene = Merge the animation of all properties from the selected layers to the selected layer with the lowest index.
# kFBAnimLayerMerge_AllLayers_CompleteScene  = Merge the animation of all properties from all the layers to the BaseAnimation layer.               

Since we used “kFBAnimLayerMerge_AllLayers_CompleteScene” all our Merged Layers were deleted leaving a clean layer stack  within the MotionBuilder take.

4 Comments

Add a Comment

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.