So as I mentioned I am doing a bit of rigging for Pete’s project (see last post). Pete’s left the file in decent shape although I find myself having to move pivot points of the meshes to the joints I wish to constrain them to. “If you have to do anything more than twice, script it” is the motto I subscribe to, so here’s a little python widget I wrote …
def moveMeshPivotsToJointPos(*args):
allSelNodes = cmds.ls(sl=True)
selectedJoints = cmds.ls( sl=True, type='joint' )
print selectedJoints
if not len(selectedJoints) == 1:
print 'Please select one joint'
else:
selectedJoint = selectedJoints[0]
cmds.select(selectedJoint, replace=True)
selJointPos = cmds.xform(query=True, rp=True, ws=True)
for eachSelNode in allSelNodes:
if not eachSelNode == selectedJoint:
print eachSelNode
cmds.select(eachSelNode, replace=True)
cmds.xform(eachSelNode, ws=True,
piv=(selJointPos[0], selJointPos[1], selJointPos[2]))
cmds.select(selectedJoint, replace=True)
cmds.select(eachSelNode, add=True)
mel.eval(cons + '-mo;')
cmds.select(cl=True)
cons = 'pointConstraint'
moveMeshPivotsToJointPos(cons)
Changing the cons variable to the name of different constraints will allow the user to dictate the moving of pivots and the type of constraint to execute, all in one shot.
I suppose a simple UI is in order to change the cons variable.
Below is a commented version of the script, so you know what each line is doing …
moveMeshPivotsToJointPos.py
