Maya Python script "LockDown"

This Maya Python script quickly toggles the selection's Transformations LOCK (Translation, Rotation and Scale) so you don't have to manually do it using the Channel Box. Assign it to a hotkey to quickly toggle lock transforms. 

___________________________


import maya.cmds as cmds


selection = cmds.ls(selection=True)


if not selection:

    cmds.warning("Select at least one object.")

else:

    attrs = [

        "translateX", "translateY", "translateZ",

        "rotateX", "rotateY", "rotateZ",

        "scaleX", "scaleY", "scaleZ"

    ]


    for obj in selection:

        # Use translateX to determine the current state

        currently_locked = cmds.getAttr(obj + ".translateX", lock=True)

        new_state = not currently_locked


        for attr in attrs:

            plug = obj + "." + attr

            if cmds.objExists(plug):

                cmds.setAttr(plug, lock=new_state)


    print("Selected object(s): {}".format(

        "LOCKED" if new_state else "UNLOCKED"

    ))