import maya.cmds as mc
import maya.mel as mel
#Instructions: Select Root Joint(s) and run script...
#[NOTE: joint chain should have "_skin" suffix]
jnts = mc.ls(sl=True, type='joint')
for jnt in jnts:
mc.select(jnt, r=True)
rootJnt = mc.ls(sl=True, type='joint')[0]
if mc.objExists('CONTROL') != True:
mc.spaceLocator(n='CONTROL')
else:
print 'Proceed'
loc = 'CONTROL'
#FK Chain
mc.select(rootJnt, r=True)
mc.duplicate(rr=True)
rootJnt_fk_node = mc.ls(sl=True, type='joint')[0]
print rootJnt_fk_node
rootJnt_fk = mc.rename(rootJnt_fk_node.replace('skin1', 'fk'))
mc.select(rootJnt_fk, hi=True)
jnts_fk = mc.ls(sl=True, type='joint')
for each_fk in jnts_fk:
rad = mc.getAttr(each_fk + '.radius')
mc.setAttr(each_fk + '.radius', rad + 0.5)
mel.eval('searchReplaceNames "skin" "fk" "hierarchy"')
fk_chain = mc.ls(sl=True, type='joint')
#IK Chain
mc.select(rootJnt, r=True)
mc.duplicate(rr=True)
rootJnt_ik_node = mc.ls(sl=True, type='joint')[0]
print rootJnt_ik_node
rootJnt_ik = mc.rename(rootJnt_ik_node.replace('skin1', 'ik'))
mc.select(rootJnt_ik, hi=True)
jnts_ik = mc.ls(sl=True, type='joint')
for each_ik in jnts_ik:
rad = mc.getAttr(each_ik + '.radius')
mc.setAttr(each_ik + '.radius', rad + 1)
mel.eval('searchReplaceNames "skin" "ik" "hierarchy"')
ik_chain = mc.ls(sl=True, type='joint')
#FK/IK Blending
mc.addAttr(loc, ln=(rootJnt + '_fkIk'), at='double', min=0, max=1)
fkIk = loc + '.' + rootJnt + '_fkIk'
print fkIk
mc.setAttr(fkIk, e=True, k=True)
mc.select(rootJnt, hi=True)
main_jnts = mc.ls(sl=True, type='joint')
for main_jnt in main_jnts:
blender = mc.createNode('blendColors', n=(main_jnt + '_fk_ik_blend'))
fk = main_jnt.replace('skin', 'fk')
ik = main_jnt.replace('skin', 'ik')
mc.connectAttr((ik + '.rotate'), (blender + '.color1'), f=True)
mc.connectAttr((fk + '.rotate'), (blender + '.color2'), f=True)
mc.connectAttr((blender + '.output'), (main_jnt + '.rotate'), f=True)
mc.connectAttr(fkIk, (blender + '.blender'), f=True)