Python Script to merge each take’s layers into the base layer

About the post

Tool to merge either an individual take or all takes layers into one layer

Date

August 11, 2024

I needed a script to automate my workflow for merging each takes layers into the base layer – this helps after finalizing a motion set and needing to clean up layers to reduce size of the ever expanding file.

Below is a python script for Motionbuilder – open the Python Editor and create a new script and then run the script (green play button) – if the script doesn’t run automatically in the terminal >> type main() and hit enter. This will then start the operation.

from pyfbsdk import *


def merge_all_layers_in_take(take):
    """
    Merge all animation layers for all models in the given take.
    -- Select each take and then merge all layers to base layer
    and delete any remaining layers.
    """

    FBSystem().CurrentTake = take
    take.MergeLayers(FBAnimationLayerMergeOptions.kFBAnimLayerMerge_AllLayers_CompleteScene, True, FBMergeLayerMode.kFBMergeLayerModeAutomatic)

def main():
    """
    Iterate over each take in the scene and merge all layers.
    """
    system = FBSystem()
    for take in system.Scene.Takes:
        merge_all_layers_in_take(take)
        print(f"All layers merged for take: {take.Name}")

if __name__ == "__main__":
    main()