Home Website Youtube GitHub

Reset rig python command

Hi there , sorry for the super simple question but i’ve been digging around the scripts trying to find this without much luck so far , how do i reset the rig with a python command?
i’m writing a simple scipt to automate a pre roll from default pose

As far as I know, there is no mGear command to do this. The menu command only resets custom attributes if you have them selected in the channel box.

Here is a quick script that should work. You might have to edit it depending on your naming conventions. Or use a selection set, instead of *_ctl.

There might be a better way. If you have a lot of controls, there might be a way to find a Maya command that can reset multiple objects at once in one single command. But since you have to query the custom attributes for each control, this is the only way I can think of:

import pymel.core as pm
from mgear.core import attribute
controllers = pm.ls('*_ctl', type='transform')
for eachControl in controllers:
    # returns the main transforms
    mainAttrs = pm.listAttr(eachControl, keyable=True)
    # returns any userDefined that are in the channelbox
    userAttrs = pm.listAttr(eachControl, userDefined=True, channelBox=True)
    channelAttrs = mainAttrs + userAttrs
    attribute.reset_selected_channels_value([eachControl], attributes=channelAttrs)

edit: note that this script will also reset non-keyable attributes, so it will change any settings on the world_ctl, like joint visibility or whatever. You might want to skip attributes that are non-keyable. That depends on your rigs.

3 Likes

There is another option available to do this. When the rig build is done, it generates a dagPose node and stores all the initial positions of the controls. You can even add your own if you need to.

import maya.cmds as cmds

# -- get the root node of the rig
rig_node = cmds.ls("*.is_rig")
if rig_node:
    # -- get the name of the rig
    rig_node = rig_node[0].split(".")[0]
    # -- query all connections, as you might add your own
    dag_poses = cmds.listConnections("{0}.rigPoses".format(rig_node))
    if dag_poses:
        # -- restore the saved positions
        cmds.dagPose(dag_poses[0], restore=True)
7 Likes

oh wow , thanks guys. I’m going to test this out asap

cheers
Sam

1 Like