Home Website Youtube GitHub

Picker buttons with custom rig (Mirroring, flipping, FK/IK Blend)

Hello everybody,

I try to connect anim picker with our rig, but it based not on mgear. I found several videos with functions of ‘mirror button’, or ‘flip button’, but it works fine with mgear setup and not with custom one. Or is it too complicated to change all this in python files ? Thanks a lot guys time and best regards
Konstantin

Flip and mirror function is using some custom attr to determine the axis that needs to be flip (also may need some other attr that store some metadata to allow any naming combination inside mGear)
image
Not sure if is better just to create your own mirror script and embed it on the anim_picker button

I try to write one or for other buttons too. All controls begins with R_ or L_ side. It makes it easier. Maybe you know better way to do this ?!

I think the most problem I will get with the FKIK blend.

### reset all ###

import maya.cmds as cmds

if not __INIT__:
# -- 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)

### reset selected ###
                
import maya.cmds as cmds

#if not __INIT__:
sel_ctrl = cmds.ls(sl=1)
for d in sel_ctrl:
    getCurrentInd = int(cmds.getAttr(''.join(d) + '.translate', se=1))
    if getCurrentInd == 1:
        cmds.setAttr(''.join(d) + '.translateX', 0)
        cmds.setAttr(''.join(d) + '.translateY', 0)
        cmds.setAttr(''.join(d) + '.translateZ', 0)
        
        cmds.setAttr(''.join(d) + '.rotateX', 0)
        cmds.setAttr(''.join(d) + '.rotateY', 0)
        cmds.setAttr(''.join(d) + '.rotateZ', 0)
        print 'yes'
    
    if getCurrentInd == 0:
        cmds.setAttr(''.join(d) + '.rotateX', 0)
        cmds.setAttr(''.join(d) + '.rotateY', 0)
        cmds.setAttr(''.join(d) + '.rotateZ', 0)
        print 'no'



### select All ###

import pymel.core as pm
#if not __INIT__:
grp = "rig_controllers_grp"
if __NAMESPACE__:
    grp = __NAMESPACE__ + ":" + grp

    members = pm.PyNode(grp).members()
    pm.select(members, r=True)


### flip ###
 
import maya.cmds as cmds

#if not __INIT__:
sel_ctrl = cmds.ls(sl=1)
for k in sel_ctrl:
    sel_xformT = cmds.xform(k, q=1, t=1)
    sel_xformTXNeg = sel_xformT[0] *-1
    sel_xformTYNeg = sel_xformT[1] *-1
    sel_xformTZNeg = sel_xformT[2] *-1
    sel_xformR = cmds.xform(k, q=1, ro=1)
    sel_xformRXNeg = sel_xformR[0] *-1
    sel_xformRYNeg = sel_xformR[1] *-1
    sel_xformRZNeg = sel_xformR[2] *-1
    rig_node = ''.join(k)[:2]
    if rig_node == 'L_':
        newFilenameL = k.replace('L_', 'R_')
        cmds.select(newFilenameL)
        cmds.xform(newFilenameL, t=(sel_xformTXNeg, sel_xformTYNeg, sel_xformTZNeg))
        cmds.xform(newFilenameL, ro=(sel_xformR[0], sel_xformRYNeg, sel_xformRZNeg))
    else :
        newFilenameR = k.replace('R_', 'L_')
        cmds.select(newFilenameR)
        cmds.xform(newFilenameR, t=(sel_xformTXNeg, sel_xformTYNeg, sel_xformTZNeg))
        cmds.xform(newFilenameR, ro=(sel_xformR[0], sel_xformRYNeg, sel_xformRZNeg))
        
    cmds.xform(k, t=(0,0,0))
    cmds.xform(k, ro=(0,0,0))
   
### flip reverse ###
 
import maya.cmds as cmds

#if not __INIT__:
sel_ctrl = cmds.ls(sl=1)
for f in sel_ctrl:
    sel_xformT = cmds.xform(f, q=1, t=1)
    sel_xformTXNeg = sel_xformT[0] *-1
    sel_xformR = cmds.xform(f, q=1, ro=1)
    sel_xformRXNeg = sel_xformR[0] *-1
    sel_xformRYNeg = sel_xformR[1] *-1
    sel_xformRZNeg = sel_xformR[2] *-1
    rig_node = ''.join(f)[:2]
    if rig_node == 'L_':
        newFilenameL = f.replace('L_', 'R_')
        cmds.select(newFilenameL)
        cmds.xform(newFilenameL, t=(sel_xformTXNeg, sel_xformT[1], sel_xformT[2]))
        cmds.xform(newFilenameL, ro=(sel_xformR[0], sel_xformRYNeg, sel_xformRZNeg))
    else:
        newFilenameR = f.replace('R_', 'L_')
        cmds.select(newFilenameR)
        cmds.xform(newFilenameR, t=(sel_xformTXNeg, sel_xformT[1], sel_xformT[2]))
        cmds.xform(newFilenameR, ro=(sel_xformR[0], sel_xformRYNeg, sel_xformRZNeg))
        
    cmds.xform(f, t=(0,0,0))
    cmds.xform(f, ro=(0,0,0))

        
### mirror ###

import maya.cmds as cmds

#if not __INIT__:
sel_ctrl = cmds.ls(sl=1)
for f in sel_ctrl:
    sel_xformT = cmds.xform(f, q=1, t=1)
    sel_xformTXNeg = sel_xformT[0] *-1
    sel_xformTYNeg = sel_xformT[1] *-1
    sel_xformTZNeg = sel_xformT[2] *-1
    sel_xformR = cmds.xform(f, q=1, ro=1)
    sel_xformRXNeg = sel_xformR[0] *-1
    sel_xformRYNeg = sel_xformR[1] *-1
    sel_xformRZNeg = sel_xformR[2] *-1
    print sel_xformTNeg
    rig_node = ''.join(f)[:2]
    if rig_node == 'L_':
        newFilenameL = f.replace('L_', 'R_')
        cmds.select(newFilenameL)
        cmds.xform(newFilenameL, t=(sel_xformTXNeg, sel_xformTYNeg, sel_xformTZNeg))
        cmds.xform(newFilenameL, ro=sel_xformR)
    else:
        newFilenameR = f.replace('R_', 'L_')
        cmds.select(newFilenameR)
        cmds.xform(newFilenameR, t=(sel_xformTXNeg, sel_xformTYNeg, sel_xformTZNeg))
        cmds.xform(newFilenameR, ro=sel_xformR)  


### mirror reverse ###

import maya.cmds as cmds

#if not __INIT__:
sel_ctrl = cmds.ls(sl=1)
for h in sel_ctrl:
    sel_xformT = cmds.xform(h, q=1, t=1)
    sel_xformTXNeg = sel_xformT[0] *-1
    sel_xformTYNeg = sel_xformT[1] *-1
    sel_xformTZNeg = sel_xformT[2] *-1
    sel_xformR = cmds.xform(h, q=1, ro=1)
    sel_xformRXNeg = sel_xformR[0] *-1
    sel_xformRYNeg = sel_xformR[1] *-1
    sel_xformRZNeg = sel_xformR[2] *-1
    rig_node = ''.join(h)[:2]
    if rig_node == 'L_':
        newFilenameL = h.replace('L_', 'R_')
        cmds.select(newFilenameL)
        cmds.xform(newFilenameL, t=(sel_xformTXNeg, sel_xformT[1], sel_xformT[2]))
        cmds.xform(newFilenameL, ro=(sel_xformR[0], sel_xformRYNeg, sel_xformRZNeg))
    else:
        newFilenameR = h.replace('R_', 'L_')
        cmds.select(newFilenameR)
        cmds.xform(newFilenameR, t=(sel_xformTXNeg, sel_xformT[1], sel_xformT[2]))
        cmds.xform(newFilenameR, ro=(sel_xformR[0], sel_xformRYNeg, sel_xformRZNeg))