wrote a Maya script to auto-generate animation layers from selection sets — never doing this by hand again

357 views 0 replies

This came out of a workflow problem eating 10–15 minutes every session. Working on a character with separate additive layers for upper body, arms, hands, and facial tweaks means creating those layers by hand, assigning the right controls, setting the right mode. It adds up. And if you accidentally nuke them (which happens more than I'd like to admit), you rebuild the whole thing from scratch.

The fix: store the control groupings as named selection sets with an _anim_ prefix, then have a script read those and reconstruct the layers on demand. Selection sets persist with the scene, so you do the grouping work once and it survives reopens.

import maya.cmds as cmds

def create_layers_from_sets(prefix="anim_", mode="additive"):
    """
    Finds all objectSets prefixed with '_anim_' and creates
    corresponding animLayers with those controls assigned.
    mode: 'additive' or 'override'
    """
    layer_mode = True if mode == "override" else False
    all_sets = cmds.ls(type='objectSet')
    anim_sets = [s for s in all_sets if s.startswith('_anim_')]

    if not anim_sets:
        cmds.warning("No selection sets with '_anim_' prefix found.")
        return []

    created = []
    for s in sorted(anim_sets):
        members = cmds.sets(s, query=True) or []
        members = cmds.ls(members, long=True)
        if not members:
            continue

        layer_name = prefix + s.replace('_anim_', '', 1)

        if cmds.objExists(layer_name):
            print(f"Layer '{layer_name}' already exists, skipping.")
            continue

        cmds.animLayer(layer_name, override=layer_mode)
        cmds.select(members, replace=True)
        cmds.animLayer(layer_name, edit=True, addSelectedObjects=True)
        created.append(layer_name)

    cmds.select(clear=True)
    print(f"Created layers: {created}")
    return created

create_layers_from_sets()

Workflow: name your selection sets _anim_upper_body, _anim_hands, _anim_face, etc. once per rig, then run the script whenever you need to rebuild. The sorted() call means layers are created alphabetically, which controls stacking order in the channel box, so naming matters. Pass mode="override" if you need full replacement layers instead of additive blending.

It's rough around the edges: no GUI, no manual ordering beyond alphabetical, doesn't handle setting initial weights. But as a one-key rebuild tool it's been genuinely useful. Anyone else managing complex anim layer setups in Maya? Curious if there's a smarter approach to the ordering problem in particular.

Moonjump
Forum Search Shader Sandbox
Sign In Register