def doSetup(baseName, numberTwistJoints, knee, hip, pelvis, hipAimAxis, hipFrontAxis, pelvisAimAxis, pelvisFrontAxis):
	try:
		# validate baseName
		utils.dg.validateNodeName(baseName)
		
		# validate incoming object names
		utils.dg.verifyNode(knee)
		utils.dg.verifyNode(hip)
		utils.dg.verifyNode(pelvis)
		
		# get the translation value for the knee
		kneeTranslate = cmds.getAttr('%s.translate'%knee)[0]
		
		# see if there is a side label
		bodySide = cmds.getAttr('%s.side'%hip)
		
		# find out what rotate order the hip is using
		rotateOrder = cmds.getAttr('%s.rotateOrder'%hip)
		
		# create the twist joints
		twistJoints = []
		
		for i in range(numberTwistJoints):
			cmds.select(cl=True)
			newJoint = cmds.joint(name='%s%s'%(baseName, i + 1))
			
			# set up the first joint
			if i == 0:
				newJoint = cmds.parent(newJoint, hip)[0]
				jointRadius = 1.0
				jointOrient = []
				if cmds.objectType(hip, isType='joint'):
					jointRadius = cmds.getAttr('%s.radius'%hip) * 0.5
	
				cmds.setAttr('%s.radius'%newJoint, jointRadius)
				cmds.setAttr('%s.jointOrient'%newJoint, 0,0,0)
				cmds.setAttr('%s.translate'%newJoint, 0,0,0)
				
				# create the hip constraint
				cmds.am_hipConstraint(
					newJoint,
					pelvisObject = pelvis,
					hipObject = hip,
					ha=hipAimAxis, 
					hf=hipFrontAxis, 
					pa=pelvisAimAxis, 
					pf=pelvisFrontAxis)
			# set up the rest of the joints
			else:
				newJoint = cmds.parent(newJoint, hip)[0]
				cmds.setAttr('%s.radius'%newJoint, jointRadius)
				cmds.setAttr('%s.jointOrient'%newJoint, 0,0,0)
				pct = float(i)/float(numberTwistJoints)
				cmds.setAttr('%s.translate'%newJoint, kneeTranslate[0]*pct, kneeTranslate[1]*pct, kneeTranslate[2]*pct)
				
				# create the orient constraint
				orientConstraint = cmds.orientConstraint([twistJoints[0], hip, newJoint])
				targetWeights = cmds.orientConstraint(q=True, weightAliasList=True)
				cmds.setAttr('%s.%s'%(orientConstraint[0], targetWeights[0]), numberTwistJoints - i)
				cmds.setAttr('%s.%s'%(orientConstraint[0], targetWeights[1]), i)
				cmds.setAttr('%s.interpType'%orientConstraint[0], 1)
				
			# set label and rotate order
			cmds.setAttr('%s.side'%newJoint, bodySide)
			cmds.setAttr('%s.type'%newJoint, 18)
			cmds.setAttr('%s.otherType'%newJoint, 'Hip Twist %s'%(i + 1), type='string')
			cmds.setAttr('%s.rotateOrder'%newJoint, rotateOrder)
			
			# add the new joint to the list to return
			twistJoints.append(newJoint)
		
		return twistJoints
	except: raise
This function creates the new twist joints and returns a list of their names.
dataset/ETHPy150Open CountZer0/PipelineConstructionSet/python/maya/site-packages/amTools/rigging/hipSetup.py/doSetup