def getAllCtrlsByParent(obj): '''given an object return all ctrls underneath it (possibly including itself)''' ctrlList = [] if ctrl.isCtrl(obj): ctrlList.append(obj) for child in cmds.listRelatives(obj, ad=True) or []: if ctrl.isCtrl(child): ctrlList.append(child) return ctrlList
def getAllCtrlsByName(filter=None): '''return a list of all ctrls. Optional name filter''' ctrlList = [] for obj in cmds.ls(type='curveShape'): par = cmds.listRelatives(obj, p=True)[0] if ctrl.isCtrl(par): if filter and not filter in par: continue ctrlList.append(par) return ctrlList
def getLimbCtrls(ctrlName): '''given a ctrl return a list of all the ctrls in that limb''' ctrls = [] limbSet = getCtrlSet(ctrlName) allSets = cmds.sets(limbSet, q=True) if not allSets: raise RuntimeError("Limb ctrls set not found, check ctrl set names") for ctrlSet in allSets: for obj in cmds.sets(ctrlSet, q=True): if ctrl.isCtrl(obj): ctrls.append(obj) return ctrls
def addAllCtrlSet(self): '''create a set with all ctrl, called when limb building is done''' allCtrls = [] for limb in self.limbs: allNodes = cmds.listRelatives(limb.limbNode, ad=True) for node in allNodes: if mpCtrl.isCtrl(node): allCtrls.append(node) self.ctrlSet = cmds.sets(em=True, n=self.rigNode + '_' + mpName.ALLCTRLSET) cmds.sets(self.ctrlSet, add=self.masterSet) cmds.sets(allCtrls, add=self.ctrlSet)
def instanceLimbNodeShape(self): '''Instance the shape under the limbNode under all limb ctrls. This gives animators easy access to limb node attrs no matter what ctrl they select. ''' limbShape = self.getLimbNodeShape() RIGLOG.debug('instancing limbNode shape %s under ctrls', limbShape) for ctrl in self.ctrls: if not mpCtrl.isCtrl(ctrl): continue inst = cmds.instance(limbShape) instShape = cmds.listRelatives(inst, s=True)[0] cmds.parent('%s|%s' % (inst[0], instShape), ctrl, s=True, r=True) cmds.delete(inst)
def __gt__(self, other): '''Override greater than (>) to do pinParent constraining''' RIGLOG.info('wiring %s', self) #Check pinParent if not self.pinParent or not cmds.objExists(self.pinParent): raise RuntimeError('Cannot wire, .pinParent not found on limb %s' % self) #If 'other' is a limb, find endJoint or fallback to startJoint: drivingNode = other if isinstance(other, Limb): if hasattr(other, 'endJoint'): drivingNode = other.endJoint elif hasattr(other, 'startJoint'): drivingNode = other.startJoint RIGLOG.debug( 'wiring found driver %s', drivingNode, ) #if that didn't work, see if 'other' is just a node: if cmds.objExists(drivingNode): RIGLOG.debug( 'wiring limb to %s', drivingNode, ) cmds.parentConstraint(drivingNode, self.pinParent, mo=True) #Try and setup pickwalk across limbs #If other is a limb use its 'endCtrl' if isinstance(other, Limb): if self.startCtrl and other.endCtrl: RIGLOG.debug('wiring pickParent from %s to %s', self.startCtrl, other.endCtrl) mpRig.addPickParent(self.startCtrl, other.endCtrl) #Otherwise grab whatever is driving 'other' and see if it's a ctrl elif cmds.objExists(other): endCtrl = mpRig.getCtrlFromJoint(other) print 'endCtrl:', endCtrl if mpCtrl.isCtrl(endCtrl): RIGLOG.debug('wiring pickParent from %s to %s', self.startCtrl, endCtrl) mpRig.addPickParent(self.startCtrl, endCtrl) else: RIGLOG.debug( 'wiring could not find pickParent on %s, skipping', other) else: RIGLOG.debug('wiring found no pickParent to connect from %s to %s', self, other)
def addLimbSets(self): '''Goes through all built limbs and creates ctrl sets for each one. Run at end of rig building by end() function. The IK and FK sets are used for easily switching IK and FK on controls. The other 'ctrls' set is just used to dump everything else, so with all three sets together every control can easily be found by animation tools. FK/IK ctrls are sorted into sets by name. It's specified here, and when the ctrls are made, by the convention in lib/name.py ''' RIGLOG.info('adding limb ctrl sets') for limb in self.limbs: ctrls = [] fkCtrls = [] ikCtrls = [] allNodes = cmds.listRelatives(limb.limbNode, ad=True) for node in allNodes: if mpCtrl.isCtrl(node): if node.endswith(mpName.FKCTRL): fkCtrls.append(node) elif node.endswith(mpName.IKCTRL): ikCtrls.append(node) else: ctrls.append(node) limbSet = cmds.sets(em=True, n=limb.limbNode + '_' + mpName.CTRLSET) cmds.sets(limbSet, add=self.masterSet) if fkCtrls: fkSet = cmds.sets(em=True, n=limb.limbNode + '_' + mpName.CTRLSETFK) cmds.sets(fkSet, add=limbSet) cmds.sets(fkCtrls, add=fkSet) if ikCtrls: ikSet = cmds.sets(em=True, n=limb.limbNode + '_' + mpName.CTRLSETIK) cmds.sets(ikSet, add=limbSet) cmds.sets(ikCtrls, add=ikSet) if ctrls: ctrlSet = cmds.sets(em=True, n=limb.limbNode + '_' + mpName.CTRLSET) cmds.sets(ctrlSet, add=limbSet) cmds.sets(ctrls, add=ctrlSet)
def getSelectedCtrls(): '''return a list of selected ctrls''' sel = cmds.ls(sl=True) or [] return [x for x in sel if ctrl.isCtrl(x)]