def locMeCvFromCvIndex(shape, cvIndex): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places locators on the cv's closest position on a curve ARGUMENTS: curve(string) RETURNS: locList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ cv = ('%s%s%i%s' % (shape, '.cv[', cvIndex, ']')) if mc.objExists(cv): cvPos = mc.pointPosition(cv, w=True) wantedName = (cv + 'loc') actualName = mc.spaceLocator(n=wantedName) mc.move(cvPos[0], cvPos[1], cvPos[2], [actualName[0]]) uPos = distance.returnClosestUPosition(actualName[0], shape) mc.move(uPos[0], uPos[1], uPos[2], [actualName[0]]) return actualName[0] else: guiFactory.warning('Shape does not exist') return False
def locMeCVOnCurve(curveCV): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places locators on the cv's closest position on a curve ARGUMENTS: curve(string) RETURNS: locList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ if search.returnObjectType(curveCV) == 'curveCV': cvPos = mc.pointPosition(curveCV, w=True) wantedName = (curveCV + '_loc') actualName = mc.spaceLocator(n=wantedName) mc.move(cvPos[0], cvPos[1], cvPos[2], [actualName[0]]) splitBuffer = curveCV.split('.') uPos = distance.returnClosestUPosition(actualName[0], splitBuffer[0]) mc.move(uPos[0], uPos[1], uPos[2], [actualName[0]]) return actualName[0] else: guiFactory.warning('Not a curveCV') return False
def doAlias(self, arg): """ Set the alias of an attribute Keyword arguments: arg(string) -- name you want to use as an alias """ assert type( arg) is str or unicode, "Must pass string argument into doAlias" if arg: try: if arg != self.nameAlias: if mc.aliasAttr(arg, self.nameCombined): self.nameAlias = arg else: guiFactory.report("'%s.%s' already has that alias!" % (self.obj.nameShort, self.attr, arg)) except: guiFactory.warning("'%s.%s' failed to set alias of '%s'!" % (self.obj.nameShort, self.attr, arg)) else: if self.nameAlias: self.attr = self.nameLong mc.aliasAttr(self.nameCombined, remove=True) self.nameAlias = False self.updateData()
def getMatchedNameObjects(self): self.matchObjectList = [] self.matchDictionaryList = [] #Get a list of objects in the scene that match the name object if len(self.objGeneratedNameDict.keys() ) <= 1 and 'cgmType' in self.objGeneratedNameDict.keys(): guiFactory.warning("There's only a type tag, ignoring match check") else: if not self.sceneObjectsNameDictMap: self.generateSceneDictMap() for k in self.sceneObjectsNameDictMap.keys(): if k not in (self.nameLong, self.nameShort): if self.sceneObjectsNameDictMap[ k] == self.objGeneratedNameDict: self.matchObjectList.append(k) self.matchDictionaryList.append( self.sceneObjectsNameDictMap[k]) elif 'cgmIterator' in self.sceneObjectsNameDictMap[k].keys( ) and returnObjectGeneratedNameDict( k, ['cgmIterator']) == self.objGeneratedNameDict: self.claimedIterators.append( int(self.sceneObjectsNameDictMap[k] ['cgmIterator'])) self.matchObjectList.append(k) self.matchDictionaryList.append( self.sceneObjectsNameDictMap[k]) self.matchesChecked = True
def doConnectIn(self, source, *a, **kw): """ Attempts to make a connection from a source to our instanced attribute Keyword arguments: source(string) - object or attribute to connect to *a, **kw """ assert mc.objExists(source), "'%s' doesn't exist" % source if '.' in source: try: attributes.doConnectAttr(source, self.nameCombined) except: guiFactory.warning("'%s' failed to connect to '%s'!" % (source, self.nameCombined)) else: #If the object has a transform matchAttr = attributes.returnMatchNameAttrsDict( self.obj.nameShort, source, [self.nameLong]) or [] if matchAttr: #If it has a matching attribute try: attributes.doConnectAttr( ('%s.%s' % (source, matchAttr.get(self.nameLong))), self.nameCombined) except: guiFactory.warning("'%s' failed to connect to '%s'!" % (source, self.nameCombined)) else: print "Source object doesn't have this particular attribute"
def doNameObject(obj,sceneUnique = False,fastIterate = True): """ Names an object ARGUMENTS: obj(string) - the object we'd like to name sceneUnique(bool)- whether to do a full scene check or just the faster check RETURNS: newName(string) on success """ ### input check assert mc.objExists(obj) is True, "'%s' doesn't exist" %obj assert mc.referenceQuery(obj, isNodeReferenced=True) is not True, "'%s' is referenced, can't name!" %obj name = returnUniqueGeneratedName(obj,sceneUnique, fastIterate) nameFactory = NameFactory(obj) if nameFactory.amIMe(name): guiFactory.warning("'%s' is already named correctly."%nameFactory.nameBase) return name else: objLong = mc.ls(obj,long=True) renameBuffer = mc.rename(objLong,name) shapes = mc.listRelatives(renameBuffer,shapes=True,fullPath=True) if shapes: for shape in shapes: if not mc.referenceQuery(shape, isNodeReferenced=True): name = returnUniqueGeneratedName(shape,sceneUnique, fastIterate) mc.rename(shape,name) return renameBuffer
def doSetUpAxis(self,i): """ Set the aim axis. if up or out have that axis. They will be changed. Aim is the priority. Then Up, and Out is last. """ assert i < 6,"%i isn't a viable up axis integer"%i assert self.aimable,"'%s' lacks this attribute"%self.nameShort axisBuffer = range(6) axisBuffer.remove(self.optionAimAxis.get()) if i != self.optionAimAxis.get(): self.optionUpAxis.set(i) else: self.optionUpAxis.set(axisBuffer[0]) guiFactory.warning("Aim axis has '%s'. Changed up axis to '%s'. Change aim setting if you want this seeting"%(dictionary.axisDirectionsByString[self.optionAimAxis.get()],dictionary.axisDirectionsByString[self.optionUpAxis.get()])) axisBuffer.remove(axisBuffer[0]) if self.optionOutAxis.get() in [self.optionAimAxis.get(),self.optionUpAxis.get()]: for i in axisBuffer: if i not in [self.optionAimAxis.get(),self.optionUpAxis.get()]: self.doSetOutAxis(i) guiFactory.warning("Setting conflict. Changed out axis to '%s'"%dictionary.axisDirectionsByString[i]) break return True
def setDragStoreMode(self, mode, debugReport=False): """ Set drag update mode """ assert bool(mode) in [True, False], "'%s' should be a bool" % mode self.dragStoreMode = mode if debugReport: guiFactory.warning("Drag store is %s!" % mode)
def returnDrivenJoints(driverAttribute): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns driven objects from a driver Attribute ARGUMENTS: obj(string) attr(string) RETURNS: attrInfo(varies) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ drivenJoints = [] attrConnections = mc.listConnections(driverAttribute, scn = True, s = False, t = 'animCurve') if attrConnections: for animCurve in attrConnections: drivenJoint = search.seekDownStream(animCurve,'joint') if mc.objExists(drivenJoint): drivenJoints.append(drivenJoint) drivenJoints = lists.returnListNoDuplicates(drivenJoints) return drivenJoints else: guiFactory.warning('No anim curves found to be connected') return False """
def doPositionLocator(locatorName,locInfo): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Position a locator with locator info generated from returnInfoForLoc ARGUMENTS: locatorName(string) locInfo(dict) RETURNS: success(bool) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ if search.returnObjectType(locatorName) == 'locator': objTrans = locInfo['position'] objRot = locInfo['rotation'] correctRo = locInfo['rotationOrder'] mc.move (objTrans[0],objTrans[1],objTrans[2], locatorName) mc.setAttr ((locatorName+'.rotateOrder'), correctRo) #Rotate if locInfo['objectType'] == 'polyFace': constBuffer = mc.normalConstraint((locInfo['createdFrom']),locatorName) mc.delete(constBuffer[0]) else: mc.rotate (objRot[0], objRot[1], objRot[2], locatorName, ws=True) return True else: guiFactory.warning('Not a locator.') return False
def __init__(self): """ Initializes the pop up menu class call """ self.optionVars = [] self.IsClickedOptionVar = OptionVarFactory("cgmVar_IsClicked", "int", 0) self.mmActionOptionVar = OptionVarFactory("cgmVar_mmAction", "int", 0) self.setupVariables() panel = mc.getPanel(up=True) if panel: # Attempt at fixing a bug of some tools not working when the pop up parent isn't 'viewPanes' if "MayaWindow" in mc.panel(panel, q=True, ctl=True): panel = "viewPanes" sel = search.selectCheck() self.IsClickedOptionVar.set(0) self.mmActionOptionVar.set(0) if mc.popupMenu("cgmMM", ex=True): mc.deleteUI("cgmMM") if panel: if mc.control(panel, ex=True): try: mc.popupMenu( "cgmMM", ctl=0, alt=0, sh=0, mm=1, b=1, aob=1, p=panel, pmc=lambda *a: self.createUI("cgmMM") ) except: guiFactory.warning("cgm.setMenu failed!")
def doNameObject(obj, sceneUnique=False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Names an object, when forceOverride is False, will select conflicting objects ARGUMENTS: obj(string) - the object we'd like to name forceOverride(bool)- whether to rename conflicts or not RETURNS: newName(string) on success >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ ### input check assert mc.objExists(obj) is True, "'%s' doesn't exist" % obj name = returnUniqueGeneratedName(obj, sceneUnique=sceneUnique) nameFactory = NameFactory(obj) if nameFactory.amIMe(name): guiFactory.warning("'%s' is already named correctly." % nameFactory.nameBase) return name else: objLong = mc.ls(obj, long=True) renameBuffer = mc.rename(objLong, name) shapes = mc.listRelatives(renameBuffer, shapes=True, fullPath=True) if shapes: for shape in shapes: name = returnUniqueGeneratedName(shape, sceneUnique=sceneUnique) mc.rename(shape, name) return renameBuffer
def getMessage(self, *a, **kw): """ Get and store attribute value as if they were messages. Used for bufferFactory to use a connected attribute as a poor man's attribute message function Keyword arguments: *a, **kw """ try: if self.form == 'message': self.value = attributes.returnMessageObject( self.obj.nameShort, self.attr) if search.returnObjectType(self.value) == 'reference': if attributes.repairMessageToReferencedTarget( self.obj.nameLong, self.attr, *a, **kw): self.value = attributes.returnMessageObject( self.obj.nameShort, self.attr) else: self.value = attributes.returnDriverAttribute( "%s.%s" % (self.obj.nameShort, self.attr)) guiFactory.report("'%s.%s' >Message> '%s'" % (self.obj.nameShort, self.attr, self.value)) return self.value except: guiFactory.warning("'%s.%s' failed to get" % (self.obj.nameShort, self.attr))
def __init__(self): """ Initializes the pop up menu class call """ self.optionVars = [] IsClickedOptionVar = OptionVarFactory('cgmVar_IsClicked', 0) mmActionOptionVar = OptionVarFactory('cgmVar_mmAction',0) panel = mc.getPanel(up = True) if panel: # Attempt at fixing a bug of some tools not working when the pop up parent isn't 'viewPanes' if 'MayaWindow' in mc.panel(panel,q = True,ctl = True): panel = 'viewPanes' sel = search.selectCheck() IsClickedOptionVar.set(0) mmActionOptionVar.set(0) if mc.popupMenu('cgmMM',ex = True): mc.deleteUI('cgmMM') if panel: if mc.control(panel, ex = True): try: mc.popupMenu('cgmMM', ctl = 0, alt = 0, sh = 0, mm = 1, b =1, aob = 1, p = panel, pmc = lambda *a: self.createUI('cgmMM')) except: guiFactory.warning('Exception on set key marking menu') mel.eval('performSetKeyframeArgList 1 {"0", "animationList"};')
def uiNameLoadedAutoNameObject(self): autoNameObject = mc.textField(self.AutoNameObjectField, q=True, text=True) if autoNameObject: newName = NameFactoryOld.doNameObject(autoNameObject, True) mc.textField(self.AutoNameObjectField, e=True, text=newName) else: guiFactory.warning('No current autoname object loaded!')
def __init__(self): """ Initializes the pop up menu class call """ self.optionVars = [] self.IsClickedOptionVar = OptionVarFactory('cgmVar_IsClicked','int',0) self.mmActionOptionVar = OptionVarFactory('cgmVar_mmAction','int',0) self.setupVariables() panel = mc.getPanel(up = True) if panel: # Attempt at fixing a bug of some tools not working when the pop up parent isn't 'viewPanes' if 'MayaWindow' in mc.panel(panel,q = True,ctl = True): panel = 'viewPanes' sel = search.selectCheck() self.IsClickedOptionVar.set(0) self.mmActionOptionVar.set(0) if mc.popupMenu('cgmMM',ex = True): mc.deleteUI('cgmMM') if panel: if mc.control(panel, ex = True): try: mc.popupMenu('cgmMM', ctl = 0, alt = 0, sh = 0, mm = 1, b =1, aob = 1, p = panel, pmc = lambda *a: self.createUI('cgmMM')) except: guiFactory.warning('cgm.setMenu failed!')
def doPositionLocator(locatorName, locInfo): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Position a locator with locator info generated from returnInfoForLoc ARGUMENTS: locatorName(string) locInfo(dict) RETURNS: success(bool) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ if search.returnObjectType(locatorName) == 'locator': objTrans = locInfo['position'] objRot = locInfo['rotation'] correctRo = locInfo['rotationOrder'] mc.move(objTrans[0], objTrans[1], objTrans[2], locatorName) mc.setAttr((locatorName + '.rotateOrder'), correctRo) #Rotate if locInfo['objectType'] == 'polyFace': constBuffer = mc.normalConstraint((locInfo['createdFrom']), locatorName) mc.delete(constBuffer[0]) else: mc.rotate(objRot[0], objRot[1], objRot[2], locatorName, ws=True) return True else: guiFactory.warning('Not a locator.') return False
def locMeCVOnCurve(curveCV): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places locators on the cv's closest position on a curve ARGUMENTS: curve(string) RETURNS: locList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ if search.returnObjectType(curveCV) == 'curveCV': cvPos = mc.pointPosition (curveCV,w=True) wantedName = (curveCV + '_loc') actualName = mc.spaceLocator (n= wantedName) mc.move (cvPos[0],cvPos[1],cvPos[2], [actualName[0]]) splitBuffer = curveCV.split('.') uPos = distance.returnClosestUPosition (actualName[0],splitBuffer[0]) mc.move (uPos[0],uPos[1],uPos[2], [actualName[0]]) return actualName[0] else: guiFactory.warning ('Not a curveCV') return False
def uiNameLoadedAutoNameObject(self): autoNameObject = mc.textField(self.AutoNameObjectField,q=True,text = True) if autoNameObject: newName = NameFactoryOld.doNameObject(autoNameObject,True) mc.textField(self.AutoNameObjectField,e = True,text = newName) else: guiFactory.warning('No current autoname object loaded!')
def doConnectIn(self,source,*a, **kw): """ Attempts to make a connection from a source to our instanced attribute Keyword arguments: source(string) - object or attribute to connect to *a, **kw """ assert mc.objExists(source),"'%s' doesn't exist"%source if '.' in source: try: attributes.doConnectAttr(source,self.nameCombined) except: guiFactory.warning("'%s' failed to connect to '%s'!"%(source,self.nameCombined)) else: #If the object has a transform matchAttr = attributes.returnMatchNameAttrsDict(self.obj.nameShort,source,[self.nameLong]) or [] if matchAttr: #If it has a matching attribute try: attributes.doConnectAttr(('%s.%s'%(source,matchAttr.get(self.nameLong))),self.nameCombined) except: guiFactory.warning("'%s' failed to connect to '%s'!"%(source,self.nameCombined)) else: print "Source object doesn't have this particular attribute"
def doConnectOut(self,target,*a, **kw): """ Attempts to make a connection from instanced attribute to a target Keyword arguments: target(string) - object or attribute to connect to *a, **kw """ assert mc.objExists(target),"'%s' doesn't exist"%target if '.' in target: try: attributes.doConnectAttr(self.nameCombined,target) except: guiFactory.warning("'%s' failed to connect to '%s'!"%(self.nameCombined,target)) else: #If the object has a transform matchAttr = attributes.returnMatchNameAttrsDict(self.obj.nameShort,target,[self.nameLong]) or [] if matchAttr: #If it has a matching attribute try: attributes.doConnectAttr(self.nameCombined,('%s.%s'%(target,matchAttr.get(self.nameLong)))) except: guiFactory.warning("'%s' failed to connect to '%s'!"%(self.nameCombined,target)) else: print "Target object doesn't have this particular attribute"
def doAlias(self,arg): """ Set the alias of an attribute Keyword arguments: arg(string) -- name you want to use as an alias """ assert type(arg) is str or unicode,"Must pass string argument into doAlias" if arg: try: if arg != self.nameAlias: if mc.aliasAttr(arg,self.nameCombined): self.nameAlias = arg else: guiFactory.report("'%s.%s' already has that alias!"%(self.obj.nameShort,self.attr,arg)) except: guiFactory.warning("'%s.%s' failed to set alias of '%s'!"%(self.obj.nameShort,self.attr,arg)) else: if self.nameAlias: self.attr = self.nameLong mc.aliasAttr(self.nameCombined,remove=True) self.nameAlias = False self.updateData()
def setKey(): KeyTypeOptionVar = OptionVarFactory('cgmVar_KeyType', defaultValue=0) KeyModeOptionVar = OptionVarFactory('cgmVar_KeyMode', defaultValue=0) if not KeyModeOptionVar.value: #This is default maya keying mode selection = mc.ls(sl=True) or [] if not selection: return guiFactory.warning('Nothing selected!') if not KeyTypeOptionVar.value: mc.setKeyframe(selection) else: mc.setKeyframe(breakdown=True) else: #Let's check the channel box for objects print 'cb mode' selection = search.returnSelectedAttributesFromChannelBox(False) or [] if not selection: selection = mc.ls(sl=True) or [] if not selection: return guiFactory.warning('Nothing selected!') if not KeyTypeOptionVar.value: mc.setKeyframe(selection) else: mc.setKeyframe(selection, breakdown=True)
def doConnectOut(self, target, *a, **kw): """ Attempts to make a connection from instanced attribute to a target Keyword arguments: target(string) - object or attribute to connect to *a, **kw """ assert mc.objExists(target), "'%s' doesn't exist" % target if '.' in target: try: attributes.doConnectAttr(self.nameCombined, target) except: guiFactory.warning("'%s' failed to connect to '%s'!" % (self.nameCombined, target)) else: #If the object has a transform matchAttr = attributes.returnMatchNameAttrsDict( self.obj.nameShort, target, [self.nameLong]) or [] if matchAttr: #If it has a matching attribute try: attributes.doConnectAttr( self.nameCombined, ('%s.%s' % (target, matchAttr.get(self.nameLong)))) except: guiFactory.warning("'%s' failed to connect to '%s'!" % (self.nameCombined, target)) else: print "Target object doesn't have this particular attribute"
def __init__(self,input): self.axisString = '' self.axisVector = '' shortStringsDict = {'x':'x+','y':'y+','z':'z+'} stringToVectorDict = {'x+':[1,0,0],'x-':[-1,0,0],'y+':[0,1,0],'y-':[0,-1,0],'z+':[0,0,1],'z-':[0,0,-1]} vectorToStringDict = {'[1,0,0]':'x+','[-1,0,0]':'x-','[0,1,0]':'y+','[0,-1,0]':'y-','[0,0,1]':'z+','[0,0,-1]':'z-'} if input in shortStringsDict.keys(): self.axisString = shortStringsDict.get(input) self.axisVector = stringToVectorDict.get(self.axisString) elif input in stringToVectorDict.keys(): self.axisVector = stringToVectorDict.get(input) self.axisString = input elif str(input) in vectorToStringDict.keys(): self.axisString = vectorToStringDict.get(str(input)) self.axisVector = stringToVectorDict.get(self.axisString) elif ' ' in list(str(input)): splitBuffer = str(input).split(' ') newVectorString = ''.join(splitBuffer) self.axisString = vectorToStringDict.get(newVectorString) self.axisVector = stringToVectorDict.get(self.axisString) else: print input print str(input) self.axisString = False self.axisVector = False guiFactory.warning("'%s' not recognized"%input)
def setDragStoreMode(self,mode,debugReport = False): """ Set drag update mode """ assert bool(mode) in [True,False],"'%s' should be a bool"%mode self.dragStoreMode = mode if debugReport:guiFactory.warning("Drag store is %s!"%mode)
def returnConstraintTargetWeights(constraint): objType = search.returnObjectType(constraint) targetsDict = {} targetList = [] constaintCmdDict = { 'parentConstraint': mc.parentConstraint, 'orientConstraint': mc.orientConstraint, 'pointConstraint': mc.pointConstraint, 'aimConstraint': mc.aimConstraint } if objType in constaintCmdDict.keys(): cmd = constaintCmdDict.get(objType) aliasList = mc.parentConstraint(constraint, q=True, weightAliasList=True) if aliasList: for o in aliasList: targetsDict[o] = mc.getAttr(constraint + '.' + o) if not targetsDict: guiFactory.warning('%s has no targets' % constraint) return False else: return targetsDict
def locMeCvFromCvIndex(shape,cvIndex): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places locators on the cv's closest position on a curve ARGUMENTS: curve(string) RETURNS: locList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ cv = ('%s%s%i%s'%(shape,'.cv[',cvIndex,']')) if mc.objExists(cv): cvPos = mc.pointPosition (cv,w=True) wantedName = (cv + 'loc') actualName = mc.spaceLocator (n= wantedName) mc.move (cvPos[0],cvPos[1],cvPos[2], [actualName[0]]) uPos = distance.returnClosestUPosition (actualName[0],shape) mc.move (uPos[0],uPos[1],uPos[2], [actualName[0]]) return actualName[0] else: guiFactory.warning ('Shape does not exist') return False
def doNameObject(obj,sceneUnique = False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Names an object, when forceOverride is False, will select conflicting objects ARGUMENTS: obj(string) - the object we'd like to name forceOverride(bool)- whether to rename conflicts or not RETURNS: newName(string) on success >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ ### input check assert mc.objExists(obj) is True, "'%s' doesn't exist" %obj name = returnUniqueGeneratedName(obj,sceneUnique = sceneUnique) nameFactory = NameFactory(obj) if nameFactory.amIMe(name): guiFactory.warning("'%s' is already named correctly."%nameFactory.nameBase) return name else: objLong = mc.ls(obj,long=True) renameBuffer = mc.rename(objLong,name) shapes = mc.listRelatives(renameBuffer,shapes=True,fullPath=True) if shapes: for shape in shapes: name = returnUniqueGeneratedName(shape,sceneUnique = sceneUnique) mc.rename(shape,name) return renameBuffer
def __init__(self,obj=''): """ Asserts objects existance and that it has a transform. Then initializes. Keyword arguments: obj(string) """ ### input check if type(obj) in [list,tuple]:#make sure it's not a list obj = obj[0] if not mc.objExists(obj): buffer = mc.group(empty=True) if len(list(obj)) < 1: obj = buffer obj = mc.rename(buffer,obj) guiFactory.warning("'%s' created as a null." %obj) self.parent = False self.children = False self.refState = False self.cgm = {} self.mType = '' self.transform = False self.update(obj)
def setKey(): KeyTypeOptionVar = OptionVarFactory('cgmVar_KeyType', defaultValue = 0) KeyModeOptionVar = OptionVarFactory('cgmVar_KeyMode', defaultValue = 0) if not KeyModeOptionVar.value:#This is default maya keying mode selection = mc.ls(sl=True) or [] if not selection: return guiFactory.warning('Nothing selected!') if not KeyTypeOptionVar.value: mc.setKeyframe(selection) else: mc.setKeyframe(breakdown = True) else:#Let's check the channel box for objects print 'cb mode' selection = search.returnSelectedAttributesFromChannelBox(False) or [] if not selection: selection = mc.ls(sl=True) or [] if not selection: return guiFactory.warning('Nothing selected!') if not KeyTypeOptionVar.value: mc.setKeyframe(selection) else: mc.setKeyframe(selection,breakdown = True)
def doLocked(self, arg=True): """ Set lock state of an attribute Keyword arguments: arg(bool) """ assert type(arg) is bool, "doLocked arg must be a bool!" if arg: if self.children: guiFactory.warning( "'%s' has children, running set command on '%s'" % (self.nameCombined, "','".join(self.children))) for c in self.children: cInstance = AttrFactory(self.obj.nameShort, c) if not cInstance.locked: mc.setAttr( (cInstance.obj.nameShort + '.' + cInstance.attr), e=True, lock=True) guiFactory.report( "'%s.%s' locked!" % (cInstance.obj.nameShort, cInstance.attr)) cInstance.locked = True self.updateData() elif not self.locked: mc.setAttr((self.obj.nameShort + '.' + self.attr), e=True, lock=True) guiFactory.report("'%s.%s' locked!" % (self.obj.nameShort, self.attr)) self.locked = True else: if self.children: guiFactory.warning( "'%s' has children, running set command on '%s'" % (self.nameCombined, "','".join(self.children))) for c in self.children: cInstance = AttrFactory(self.obj.nameShort, c) if cInstance.locked: mc.setAttr( (cInstance.obj.nameShort + '.' + cInstance.attr), e=True, lock=False) guiFactory.report( "'%s.%s' unlocked!" % (cInstance.obj.nameShort, cInstance.attr)) cInstance.locked = False self.updateData() elif self.locked: mc.setAttr((self.obj.nameShort + '.' + self.attr), e=True, lock=False) guiFactory.report("'%s.%s' unlocked!" % (self.obj.nameShort, self.attr)) self.locked = False
def reset(self, debugReport=False): """ Reset data """ self.createdList = [] self.returnList = [] if debugReport: guiFactory.warning("'%s' reset." % self.name)
def reset(self,debugReport = False): """ Reset data """ self.createdList = [] self.returnList = [] if debugReport:guiFactory.warning("'%s' reset."%self.name)
def doUpdateObjectName(self): selected = mc.ls(sl=True) for obj in selected: try: NameFactoryOld.doUpdateName(obj) except: guiFactory.warning('Error on naming attempt')
def uiCopyTags(self): selected = mc.ls(sl=True) if len(selected) >= 2: for obj in selected[1:]: print obj attributes.copyNameTagAttrs(selected[0], obj) else: guiFactory.warning('Need at least two objects.')
def uiNameLoadedAutoNameObjectChildren(self): autoNameObject = mc.textField(self.AutoNameObjectField, q=True, text=True) if autoNameObject: newNameList = NameFactoryOld.doRenameHeir(autoNameObject, True) mc.textField(self.AutoNameObjectField, e=True, text=newNameList[0]) else: guiFactory.warning('No current autoname object loaded!')
def reset(self): """ Reset data """ self.createdList = [] self.returnList = [] guiFactory.warning("'%s' reset."%self.name)
def uiNameLoadedAutoNameObjectChildren(self): autoNameObject = mc.textField(self.AutoNameObjectField,q=True,text = True) if autoNameObject: newNameList = NameFactoryOld.doRenameHeir(autoNameObject,True) mc.textField(self.AutoNameObjectField,e = True,text = newNameList[0]) else: guiFactory.warning('No current autoname object loaded!')
def remove(self,attr): """ Removes an attr from the maya object instanced. """ if self.refState: return guiFactory.warning("'%s' is referenced. Cannot delete attrs"%self.nameShort) try: attributes.doDeleteAttr(self.nameLong,attr) except: guiFactory.warning("'%s.%s' not found"%(self.nameLong,attr))
def uiCopyTags(self): selected = mc.ls(sl=True) if len(selected) >= 2: for obj in selected[1:]: print obj attributes.copyNameTagAttrs(selected[0],obj) else: guiFactory.warning('Need at least two objects.')
def doObjToTargetFunctionOnSelected(function,**a): bufferList = [] selected = mc.ls (sl=True,flatten=True) or [] mc.select(cl=True) if len(selected) >=2: for item in selected[:-1]: bufferList.append(function(item,selected[-1])) mc.select(selected) return bufferList else: guiFactory.warning('You must have at least two objects selected')
def reorderAttributes(obj, attrs, direction=0): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Acknowledgement: Thank you to - http://www.the-area.com/forum/autodesk-maya/mel/how-can-we-reorder-an-attribute-in-the-channel-box/ DESCRIPTION: Reorders attributes on an object ARGUMENTS: obj(string) - obj with message attrs attrs(list) must be attributes on the object direction(int) - 0 is is negative (up on the channelbox), 1 is positive (up on the channelbox) RETURNS: messageList - nested list in terms of [[attrName, target],[etc][etc]] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ assert direction in [ 0, 1 ], "Direction must be 0 for negative, or 1 for positive movement" for attr in attrs: assert cmds.objExists( obj + '.' + attr) is True, "'%s.%s' doesn't exist. Swing and a miss..." % (obj, atr) userAttrs = cmds.listAttr(obj, userDefined=True) attrsToMove = [] for attr in userAttrs: if not cmds.attributeQuery(attr, node=obj, listParent=True): attrsToMove.append(attr) lists.reorderListInPlace(attrsToMove, attrs, direction) #To reorder, we need delete and undo in the order we want for attr in attrsToMove: try: attrBuffer = '%s.%s' % (obj, attr) lockState = False if cmds.getAttr(attrBuffer, lock=True) == True: lockState = True cmds.setAttr(attrBuffer, lock=False) cmds.deleteAttr('%s.%s' % (obj, attr)) cmds.undo() if lockState: cmds.setAttr(attrBuffer, lock=True) except: guiFactory.warning("'%s' Failed to reorder" % attr)
def doObjToTargetFunctionOnSelected(function, **a): bufferList = [] selected = mc.ls(sl=True, flatten=True) or [] mc.select(cl=True) if len(selected) >= 2: for item in selected[:-1]: bufferList.append(function(item, selected[-1])) mc.select(selected) return bufferList else: guiFactory.warning('You must have at least two objects selected')
def purge(self): """ Purge an optionVar from maya """ try: mc.optionVar(remove = self.name) self.name = '' self.form = '' self.value = '' except: guiFactory.warning("'%s' doesn't exist"%(self.name))
def doNameHeirarchy(self, sceneUnique=False, fastIterate=True): selected = mc.ls(sl=True) if not selected: guiFactory.warning('Must have something selected') return for obj in selected: try: NameFactoryOld.doRenameHeir(obj, sceneUnique, fastIterate) except: guiFactory.warning('Error on naming attempt')
def doDelete(self): """ Deletes an attribute """ try: attributes.doDeleteAttr(self.obj.nameShort,self.attr) guiFactory.warning("'%s.%s' deleted"%(self.obj.nameShort,self.attr)) self.value = None return self.value except: guiFactory.warning("'%s.%s' failed to delete"%(self.obj.nameShort,self.attr))
def doNameHeirarchy(self,sceneUnique=False,fastIterate=True): selected = mc.ls(sl=True) if not selected: guiFactory.warning('Must have something selected') return for obj in selected: try: NameFactoryOld.doRenameHeir(obj,sceneUnique,fastIterate) except: guiFactory.warning('Error on naming attempt')
def doCopyTo(self,target, targetAttrName = None, convertToMatch = True, values = True, incomingConnections = False, outgoingConnections = False, keepSourceConnections = True, copyAttrSettings = True, connectSourceToTarget = False): """ Replacement for Maya's since maya's can't handle shapes....blrgh... Copy attributes from one object to another as well as other options. If the attribute already exists, it'll copy the values. If it doesn't, it'll make it. If it needs to convert, it can. It will not make toast. Keywords: toObject(string) - obj to copy to targetAttrName(string) -- name of the attr to copy to . Default is None which will create an attribute of the fromAttr name on the toObject if it doesn't exist convertToMatch(bool) -- whether to convert if necessary.default True values(bool) -- copy values. default True incomingConnections(bool) -- default False outGoingConnections(bool) -- default False keepSourceConnections(bool)-- keeps connections on source. default True copyAttrSettings(bool) -- copy the attribute state of the fromAttr (keyable,lock,hidden). default True connectSourceToTarget(bool) useful for moving attribute controls to another object. default False RETURNS: success(bool) """ assert mc.objExists(target),"'%s' doesn't exist"%target assert mc.ls(target,long=True) != [self.obj.nameShort], "Can't transfer to self!" copyTest = [values,incomingConnections,outgoingConnections,keepSourceConnections,connectSourceToTarget,copyAttrSettings] if sum(copyTest) < 1: guiFactory.warning("You must have at least one option for copying selected. Otherwise, you're looking for the 'doDuplicate' function.") return False if '.' in list(target): targetBuffer = target.split('.') if len(targetBuffer) == 2: attributes.doCopyAttr(self.obj.nameShort, self.nameLong, targetBuffer[0], targetBuffer[1], convertToMatch, values, incomingConnections, outgoingConnections, keepSourceConnections, copyAttrSettings, connectSourceToTarget) else: guiFactory.warning("Yeah, not sure what to do with this. Need an attribute call with only one '.'") else: attributes.doCopyAttr(self.obj.nameShort, self.nameLong, target, targetAttrName, convertToMatch, values, incomingConnections, outgoingConnections, keepSourceConnections, copyAttrSettings, connectSourceToTarget)
def doSetOutAxis(self,i): assert i < 6,"%i isn't a viable aim axis integer"%i assert self.aimable,"'%s' lacks this attribute"%self.nameShort if i not in [self.optionAimAxis.get(),self.optionUpAxis.get()]: self.optionOutAxis.set(i) else: axisBuffer = range(6) axisBuffer.remove(self.optionAimAxis.get()) axisBuffer.remove(self.optionUpAxis.get()) self.optionOutAxis.set(axisBuffer[0]) guiFactory.warning("Setting conflict. Changed out axis to '%s'"%dictionary.axisDirectionsByString[ axisBuffer[0] ])
def uiAutoNameWalkUp(self): autoNameObject = mc.textField(self.AutoNameObjectField,q=True,text = True) if autoNameObject: parent = search.returnParentObject(autoNameObject,False) if parent: mc.textField(self.AutoNameObjectField,e=True,text = parent) mc.select(parent) uiUpdateAutoNamePreview(self) uiLoadAutoNameObject(self) else: guiFactory.warning('No parent found!') else: guiFactory.warning('No current autoname object loaded!')