splinecraft
12/8/2016 - 8:43 PM

Anim layers example to query and create new layer if it doesn't already exist From https://www.safaribooksonline.com/library/view/maya-progr

Anim layers example to query and create new layer if it doesn't already exist From https://www.safaribooksonline.com/library/view/maya-programming-with/9781785283987/ch06s03.html

import maya.cmds as cmds

def makeAnimLayer(layerName):

    baseAnimationLayer = cmds.animLayer(query=True, root=True)

    foundLayer = False

    if (baseAnimationLayer != None):
        childLayers = cmds.animLayer(baseAnimationLayer, query=True, children=True)

        if (childLayers != None) and (len(childLayers) > 0):
            if layerName in childLayers:
                foundLayer = True

    if not foundLayer:
        cmds.animLayer(layerName)
    else:
        print('Layer ' + layerName + ' already exists')

makeAnimLayer("myLayer")