def _targetMatch(self, *args): args=pm.ls(sl=True) for arg in args: if pm.objExists(arg+'.target'): tgt= pm.PyNode(arg.target.get()) elif pm.objExists(nami.replaceSuffix(arg+'GEO')): tgt = pm.PyNode(arg.target.get()) else: print 'Couldn\'t find target for object: %s ...skipping' % arg break posi.matchPos(arg, [tgt], 1)
def duplicateAcross(src='', args=[], instance=False): ''' Function: takes a source and matchesPos + duplicates it onto all args Args = src=string/PyNode, args=list of strings/PyNodes, instance=boolean State: instance=True: uses instances instead of straight duplicates Returns: None Usage: duplicateAcross() duplicateAcross('pSphere1', pm.ls(sl=True), instance=True) ''' if args==[] or src=='': args=pm.ls(sl=True)[1:] src=pm.ls(sl=True)[0] for arg in args: srcDup = pm.duplicate(src, returnRootsOnly=True, upstreamNodes=True, instanceLeaf=instance) srcDup[0].setParent(None) posi.matchPos(arg, [srcDup], type=1) help(nami.replaceSuffix)
def rig_piston(head, rod, weight, crankshaft, rotatePattern, parent=False): rod_grp = pm.group(em=True,n=rod.replace('LOC','GRP')) head_grp = pm.group(em=True,n=head.replace('LOC','GRP')) head_pos = pm.spaceLocator(n=head.replace('LOC','pos_LOC')) pos.matchPos(head, [head_pos]) pos.matchPos(rod, [rod_grp], type=1, ws=True, silent=True) rod.setParent(rod_grp) pos.matchPos(head, [head_grp]) head.setParent(head_grp) pm.parentConstraint(weight, rod_grp, skipRotate=('x','y','z'),mo=True) pm.aimConstraint(head, rod, aimVector=(0,1,0), upVector=(0,1,0), worldUpType='vector',worldUpVector=(0,1,0), offset=(0,0,0),weight=1,skip=('y','z'), mo=True) dist=pm.shadingNode('distanceBetween',asUtility=True) head_pos.translate.connect(dist.point1) rod_grp.translate.connect(dist.point2) pma = pm.shadingNode('plusMinusAverage',asUtility=True) pma.input2D[1].input2Dx.set( dist.distance.get()) dist.distance.connect( pma.input2D[0].input2Dx) pma.operation.set(2) md = pm.shadingNode("multiplyDivide", asUtility=True) pma.output2D.output2Dx.connect(md.input1.input1X) md.input2.input2X.set(-1) md.outputX.connect(head.ty) head_pos.visibility.set(0) if parent: rod_grp.setParent(parent) head_grp.setParent(parent) head_pos.setParent(parent) if rotatePattern: #Same direction if the input is 0 crankshaft.rotateX.connect(weight.rotateX) else: #Reverse if the input is 0 md = pm.shadingNode('multiplyDivide',asUtility=True) crankshaft.rotateX.connect(md.input1X) md.outputX.connect(weight.rotateX) md.input2X.set(-1)
def xpop(args=[], type='LOC', space=1, addSuffix='', parent=''): ''' Function: takes args and matchesPos + duplicates specified type onto each arg Args = type=str, space=int, addSuffix=str, parent=str State: type=one of ['LOC','PLANE','CUBE','JNT','GRP','CAM','SLGT','DLGT','PLGT','ALGT'] if in list of prespecified objects, will populate across. Explained: locator, plane, cube, joint, group, camera, spotlight, directional light, point light, area light space=1-4: check help for _SCRIPTS._LAYOUT.lib_position.matchPos for instruction on this otherwise leave default Returns: list of PyNode(type) Example Usage: xpop(type='JNT', addSuffix='TEMP') ''' print 'Populating type: %s' % type suffixes=['LOC','PLANE','CUBE','JNT','GRP','CAM','SLGT','DLGT','PLGT','ALGT'] if type.upper() in suffixes or pm.objExists(type): if args==[]: args = pm.ls(sl=True) #Create or store group if parent=='': grp = 'populate_'+type+'_GRP' else: grp = parent if not pm.objExists(grp): grp = pm.group(em=True, n=grp) else: grp = pm.PyNode(grp) result=[] print type for arg in args: if addSuffix=='': pop = nami.replaceSuffix(type,args=arg.name(),validSuffix=True) else: pop = arg.name()+addSuffix if not pm.objExists(pop): if type=='LOC': pop = pm.spaceLocator(n=pop) elif type=='PLANE': pop = pm.polyPlane(n=pop,sx=1, sy=1)[0] elif type=='CUBE': pop = pm.polyCube(n=pop)[0] elif type=='JNT': pop = pm.joint( n=pop ) pop.radius.set(10) elif type=='GRP': pop = pm.group(em=True,n=pop) elif type=='CAM': pop = pm.camera(n=pop)[0] elif type=='SLGT': pop = pm.spotLight().listRelatives(p=True)[0].rename(pop) elif type=='DLGT': pop = pm.directionalLight().listRelatives(p=True)[0].rename(pop) elif type=='PLGT': pop = pm.pointLight().listRelatives(p=True)[0].rename(pop) elif type=='ALGT': pop = pm.createNode('areaLight').listRelatives(p=True)[0].rename(pop) else: pop = pm.duplicate(type)[0] posi.matchPos(src=arg, args=[pop], type=1) pop.addAttr('target',dt='string') pop.target.set( arg ) pop.setParent( grp ) result.append(pop) else: pm.error('Unsupported object type, check the help() for supported types') return result