Code Snipets

Table of Contents

IMPORT MT

				
					import Mutant_Tools
import Mutant_Tools.Utils.Rigging
from Mutant_Tools.Utils.Rigging import main_mutant
imp.reload(Mutant_Tools.Utils.Rigging.main_mutant)

mt = main_mutant.Mutant() 
nc, curve_data, setup = mt.import_configs()
				
			

GET ATTRS

				
					    ctrl_size = cmds.getAttr('{}.CtrlSize'.format(config))
    ctrl_type = cmds.getAttr('{}.CtrlType'.format(config), asString = True)
 
				
			

CREATE ATTRS

				
					rfl_temp_attr = mt.new_attr(input= ik_attrs_shape, name = attr, min = -100 , max = 100, default = 0)
show_gimbal_attr = mt.new_enum(input= ctrl, name = 'Gimbal', enums = 'Hide:Show') 
				
			

CONNECT MULTIPLY DIVIDE NODES

				
					mt.connect_md_node(in_x1=up_limit, in_x2=-1, out_x=upper_pivot_joint+'.minRotLimit.minRotZLimit', mode='multiply')

				
			

CLEAN ATTRS IN CTRLS

				
					mt.hide_attr(input=jaw_ctrl, s=True)
				
			

CREATE CTRLS

				
					ctrl = mt.curve(  input=joint,
                          type='cube',
                          rename=True,
                          custom_name=True,
                          name=joint.replace(nc['joint'], nc['ctrl']),
                          size=size)

mt.assign_color(color=color)
root_grp = mt.root_grp()[0]
mt.match(root_grp, joint, r=True, t=True)
cmds.parentConstraint(ctrl, joint)
				
			

CLEAN THE RIG AT THE END

				
					    clean_ctrl_grp = cmds.group(em=True, name = name + nc['ctrl'] + nc['group'])
    clean_rig_grp = cmds.group(em=True, name = name + '_Rig' + nc['group'])

    cmds.parent(clean_rig_grp, '{}{}'.format(setup['rig_groups']['misc'], nc['group']))
    cmds.parent(clean_ctrl_grp, setup['base_groups']['control'] + nc['group']) 
				
			

SET COLORS

				
					        if side_guide.startswith(nc['right']):
            color='red'
        elif side_guide.startswith(nc['left']):
            color='blue'
        else:
            color = 'yellow'
        mt.assign_color(color=color) 
				
			

MIRROR SYSTEMS

				
					#check if the mirror attrs to Only_Right or mirror to True
        if cmds.getAttr('{}.Mirror'.format(config), asString = True) == 'Right_Only':

            mirror_ctrl_grp = mt.mirror_group(clean_ctrl_grp, world = True)
            cmds.parentConstraint(block_parent, ikfk['ik_fk'][5][0] , mo = True)
            cmds.parentConstraint(block_parent, cmds.listRelatives(ikfk['ik_fk'][4][2], p=True) , mo = True)
            clean_ctrl_grp = mirror_ctrl_grp


        elif cmds.getAttr('{}.Mirror'.format(config), asString = True) == 'True':
            ''
            if str(side_guide).startswith(nc['right']) :
                mirror_ctrl_grp = mt.mirror_group(clean_ctrl_grp, world = True)

                cmds.parentConstraint(block_parent, ikfk['ik_fk'][5][0] , mo = True)
                cmds.parentConstraint(block_parent, cmds.listRelatives(ikfk['ik_fk'][4][2], p=True) , mo = True)
                cmds.orientConstraint(block_parent, ikfk['upper_twist']['no_rotate'] , mo = True)

                clean_ctrl_grp = mirror_ctrl_grp
            else:
                cmds.parentConstraint(block_parent, ikfk['ik_fk'][5][0] , mo = True)
                cmds.parentConstraint(block_parent, cmds.listRelatives(ikfk['ik_fk'][4][2], p=True) , mo = True)
                cmds.orientConstraint(block_parent, ikfk['upper_twist']['no_rotate'] , mo = True)


        else: #only left side

                cmds.parentConstraint(block_parent, ikfk['ik_fk'][5][0] , mo = True)
                cmds.parentConstraint(block_parent, cmds.listRelatives(ikfk['ik_fk'][4][2], p=True) , mo = True)
                cmds.orientConstraint(block_parent, ikfk['upper_twist']['no_rotate'] , mo = True) 
				
			

CREATE BIND JOINTS

				
					        # create bind joints
        bind_jnt_grp = '{}{}'.format(setup['rig_groups']['bind_joints'], nc['group'])
        for jnt in tweek_joints:
            cmds.select(cl=True)
            bind_joint = cmds.joint(n=jnt.replace(nc['joint'], nc['joint_bind']))
            cmds.parentConstraint(jnt, bind_joint)
            cmds.scaleConstraint(jnt, bind_joint)
            cmds.setAttr('{}.radius'.format(bind_joint), 1.5)
            cmds.parent(bind_joint, bind_jnt_grp) 
				
			

VIS SWITCHES

				
					#vis
    attrs_position = cmds.getAttr('{}.SetAttrsPosition'.format(config), asString=True)

    if attrs_position == 'new_locator':
        guide_attrs_position = cmds.spaceLocator(n=name + '_Attrs' + nc['locator'])[0]

    mt.line_attr(input=guide_attrs_position, name='Nose_Vis')
    main_ctrl_attr = mt.new_enum(input=guide_attrs_position, name='noseMainCtrls', enums='Hide:Show')
    mid_ctrl_attr = mt.new_enum(input=guide_attrs_position, name='noseMidCtrls', enums='Hide:Show')
    show_tweeks_attr = mt.new_enum(input=guide_attrs_position, name='noseTweekCtrls', enums='Hide:Show')

    for ctrl in main_controllers:
        shape = cmds.listRelatives(ctrl, s=True)[0]
        cmds.connectAttr(main_ctrl_attr, '{}.v'.format(shape))
    for ctrl in sec_ctrls:
        shape = cmds.listRelatives(ctrl, s=True)[0]
        cmds.connectAttr(mid_ctrl_attr, '{}.v'.format(shape))
    for ctrl in tweek_controllers:
        shape = cmds.listRelatives(ctrl, s=True)[0]
        cmds.connectAttr(show_tweeks_attr, '{}.v'.format(shape)) 
				
			

SHARED LOCATOR ATTRS

				
					  all_controllers =  [chest_ctrl, belly_ctrl, base_ctrl, base_ik_ctrl] + spine_ik_ctrls
    for ctrl in all_controllers:
        cmds.select(ctrl)
        if cmds.objectType(ctrl) == 'transform':
            spine_attrs_loc = mt.shape_with_attr(input='', obj_name='{}_Attrs'.format(name), attr_name='').split('.')[0]
    print(spine_attrs_loc) 
				
			

SPACE SWITCHES

				
					#Space switches
    # compatible with older versions without spaces
    if cmds.attributeQuery('SpaceSwitches', n=config, exists=True):
        space_parents = cmds.getAttr('{}.SpaceSwitches'.format(config))
    else:
        space_parents = "Global_Ctrl:BlockParent"
        if cmds.objExists('COG_Ctrl'):
            space_parents = "Global_Ctrl:COG_Ctrl:BlockParent"

    #Add shared loc
    all_controllers = eyes_ctrls + [main_eye_ctrl]
    for ctrl in all_controllers:
        cmds.select(ctrl)
        if cmds.objectType(ctrl) == 'transform':
            spine_attrs_loc = mt.shape_with_attr(input='', obj_name='{}_Attrs'.format(name), attr_name='Test').split('.')[0]
    mel.eval('catch (`deleteAttr -attribute "Test" "{}|Spine_Attrs_Loc"`);'.format(main_eye_ctrl))
    space_attr = mt.new_enum(input=spine_attrs_loc, name='SpaceSwitch', enums=space_parents)

    #add attrs
    ctrl = main_eye_ctrl
    offset = main_eye_root
    root, auto = mt.root_grp(input=ctrl, autoRoot=True)

    spaces_grp = cmds.group(em=True, n=name+'SpaceSwitches' + nc['group'])

    print('SpaceSwitches:', space_parents)

    space_parents = space_parents.replace('BlockParent', block_parent)
    spaces = space_parents.split(':')
    for num, space in enumerate(spaces):
        space_loc = cmds.spaceLocator(n=name + space + '_SpaceSwitch' + nc['locator'])[0]
        cmds.parent(space_loc, spaces_grp)

        cmds.parentConstraint(space, space_loc, mo=True)[0]
        oc = cmds.orientConstraint(space_loc, auto, mo=True)[0]

        cmds.setAttr('{}.interpType'.format(oc), 2)

        condition_node = cmds.shadingNode('condition', asUtility=True, n=name + space + nc['condition'])
        cmds.setAttr('{}.operation'.format(condition_node), 0)
        cmds.setAttr('{}.colorIfTrueR'.format(condition_node), 1)
        cmds.setAttr('{}.colorIfFalseR'.format(condition_node), 0)
        cmds.setAttr('{}.secondTerm'.format(condition_node), num)

        cmds.connectAttr(space_attr, '{}.firstTerm'.format(condition_node))
        cmds.connectAttr('{}.outColorR'.format(condition_node), '{}.{}W{}'.format(oc, space_loc, num))

    cmds.parent(spaces_grp, clean_rig_grp)