Posts Tagged Rigging

A little bit of python for Pete

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

Tags: , , ,

2 Comments

Pete’s secret project

My co-worker and buddy Pete has a project he’s working on in his free time.  He suckered me into asked me if I’d be interested in rigging it.  I just started out, and it’ll have some intersting challenges.  I’ll update as I progress.2009-04-10_2308

Tags:

1 Comment