def getMelPath(self): if self.melPath==[] and _mayaNative: if system()[:3].lower()=='win': seperator=';' else: seperator=':' self.melPath=getReversed(mel.eval('getenv("MAYA_SCRIPT_PATH")').split(seperator)) return self.melPath
def hierarchyOrder(*args, **keywords): reverse = False shortNames = {"r": "reverse"} for k in keywords: if k in locals(): exec(k + "=keywords[k]") elif k in shortNames: exec(shortNames[k] + "=keywords[k]") if len(args) == 0: args = mc.ls(sl=True) sel = [] for a in args: sel.extend(iterable(a)) sel = removeDuplicates(mc.ls(sel, type="dagNode")) if len(sel) < 2: return sel sorted = [] unsorted = list(sel) i = 0 while len(unsorted) > 0: used = [] for x in unsorted: if len(x.split("|")) == i: sorted.append(x) used.append(x) unsorted = removeAll(used, unsorted) i += 1 if reverse: return getReversed(sorted) else: return sorted
def __init__(self,*args,**keywords): #check to make sure unique names are used in scene uniqueNames(iterable(mc.ls(type='dagNode')),re=True) #default options self.number=1 #if there are no transforms, create this many rivets self.distribute='' self.parents=['',''] self.rebuild=False self.taper='none' # none, normal, distance self.scale='none' # none, uniform, or relative self.scaleDirection=['length','width'] # length, width self.createAimCurve=False self.aimCurve='' self.handles=[] self.handleShapes=[] self.autoFlexGroups=[] self.mo=True # maintain offset self.ctrls=[] #by default control attributes are placed on given transforms self.keepPivot=True self.snapToSurface=False self.realign=False self.rivets=[] self.ClosestPoints=[] self.aimGroups=[] self.softParents=[] self.ArcCtrl=[] self.arcWeight=.5 self.closestPoint='' # geometry, pivot self.organize=True self.constraint=False # use a parent constraint self.parent=False # create a transform and parent objects to it self.spaceTr='' self.surfaceAttr='' self.bindPoses=[] self.parentSpaces=[] self.hasGeometry=True self.skipRotate=[] self.skipTranslate=[] self.skipScale=[] self.skipScaleObjects=[] self.skipRotateObjects=[] self.skipTranslateObjects=[] self.minScaleWidth=0 self.maxScaleWidth=1 self.minScaleLength=0 self.maxScaleLength=1 self.surfaceMatrix='' self.surfaceInverseMatrix='' self.worldMatrix='' self.trs=[] self.uSpans=-1 self.vSpans=-1 self.skins=[] self.shortNames=\ { 'sd':'scaleDirection', 'p':'parents', 'sp':'softParents' } sel=[] if len(args)==0: sel=mc.ls(sl=True) for a in args: sel.extend(iterable(a)) self.bindPoses=iterable(getBindPoses(sel)) if len(self.bindPoses)>0: goToDagPose(self.bindPoses[0]) self.edges=PolyEdgeList(sel,f=True) self.trs=removeDuplicates(mc.ls(self.edges.etcObj,tr=True)) if len(self.edges)==0: #look for a surface or surface attribute reversedObjList=getReversed(self.edges.etcObj) for obj in reversedObjList: if len(obj.split('.'))>1 and mc.getAttr(obj,type=True)=='nurbsSurface': self.surfaceAttr=obj obj=mc.ls(self.surfaceAttr,o=True)[0] if mc.nodeType(obj)=='nurbsSurface': self.uSpans=mc.getAttr(obj+'.spansU') self.vSpans=mc.getAttr(obj+'.spansV') self.spaceTr=mc.listRelatives(obj,p=True)[0] break elif mc.nodeType(obj)=='nurbsSurface': self.surfaceAttr=obj+'.worldSpace[0]' self.spaceTr=mc.listRelatives(obj,p=True)[0] self.uSpans=mc.getAttr(obj+'.spansU') self.vSpans=mc.getAttr(obj+'.spansV') self.trs.remove(obj) break else: children=mc.listRelatives(obj,c=True,s=True,ni=True,type='nurbsSurface') if isIterable(children) and len(children)>0: self.spaceTr=mc.ls(obj)[0] self.surfaceAttr=children[0]+'.worldSpace[0]' self.uSpans=mc.getAttr(children[0]+'.spansU') self.vSpans=mc.getAttr(children[0]+'.spansV') self.trs.remove(obj) break else: self.spaceTr=self.edges.getTr() for k in keywords: if k in self.__dict__: exec('self.'+k+'=keywords[k]') elif k in self.shortNames: exec('self.'+self.shortNames[k]+'=keywords[k]') if len(iterable(self.parents))==1: self.parents=[iterable(self.parents)[0],iterable(self.parents)[0]] if len(iterable(self.softParents))==1: self.softParents=[iterable(self.softParents)[0],iterable(self.softParents)[0]] if len(self.ctrls)==0: self.ctrls=self.trs while len(self.ctrls)<len(self.trs): self.ctrls.append(self.ctrls[-1]) if len(self.skipRotate)>0: for i in self.skipRotate: self.skipRotateObjects.append(self.trs[self.skipRotate[i]]) if len(self.skipTranslate)>0: for i in self.skipTranslate: self.skipTranslateObjects.append(self.trs[self.skipTranslate[i]]) if len(self.skipScale)>0: for i in self.skipScale: self.skipScaleObjects.append(self.trs[self.skipScale[i]]) if len(self.trs)>0: for t in self.trs: shCount=len\ ( removeDuplicates(mc.listRelatives(t,c=True,type='nurbsSurface'))+ removeDuplicates(mc.listRelatives(t,c=True,type='nurbsCurve'))+ removeDuplicates(mc.listRelatives(t,c=True,type='mesh')) ) if shCount==0: self.hasGeometry=False self.closestPoint='pivot' break if self.closestPoint=='' and self.hasGeometry: # default to pivot if using snap to surface, otherwise defualts to geometry if self.snapToSurface: self.closestPoint='pivot' else: self.closestPoint='geometry' if len(self.trs)!=0: self.number=len(self.trs) if len(self.ctrls)<len(self.trs): self.ctrls=self.trs if not self.parent and not self.constraint: self.parent=True if self.createAimCurve: self.parent=True #self.constraint=False #find the root joint if present try: joints=removeDuplicates(mc.listConnections(iterable(mc.ls(iterable(mc.listHistory(self.surfaceAttr)))),type='joint')) if len(joints)>0: self.spaceTr=hierarchyOrder(joints)[0] except: pass self.create()