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 purge(self): """ Purge all buffer attributes from an object """ userAttrs = mc.listAttr(self.nameLong, userDefined=True) or [] for attr in userAttrs: if 'item_' in attr: attributes.doDeleteAttr(self.nameLong, attr) guiFactory.warning("Deleted: '%s.%s'" % (self.nameLong, attr)) self.bufferList = [] self.bufferDict = {}
def purge(self): """ Purge all buffer attributes from an object """ userAttrs = mc.listAttr(self.nameLong,userDefined = True) or [] for attr in userAttrs: if 'item_' in attr: attributes.doDeleteAttr(self.nameLong,attr) guiFactory.warning("Deleted: '%s.%s'"%(self.nameLong,attr)) self.bufferList = [] self.bufferDict = {}
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 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 remove(self,info,*a,**kw): """ Store information to an object in maya via case specific attribute. """ if info not in self.bufferList: guiFactory.warning("'%s' isn't already stored '%s'"%(info,self.nameLong)) return for key in self.bufferDict.keys(): if self.bufferDict.get(key) == info: attributes.doDeleteAttr(self.nameLong,key) self.bufferList.remove(info) self.bufferDict.pop(key) guiFactory.warning("'%s' removed!"%(info)) self.updateData()
def remove(self, info, *a, **kw): """ Store information to an object in maya via case specific attribute. """ if info not in self.bufferList: guiFactory.warning("'%s' isn't already stored '%s'" % (info, self.nameLong)) return for key in self.bufferDict.keys(): if self.bufferDict.get(key) == info: attributes.doDeleteAttr(self.nameLong, key) self.bufferList.remove(info) self.bufferDict.pop(key) guiFactory.warning("'%s' removed!" % (info)) self.updateData()
def doPurgeNull(null): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Delete all non 'cgm' type user attributes on an object ARGUMENTS: moduleNull(string) RETURNS: infoNullDict(dict) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ userAttrsData = attributes.returnUserAttrsToDict(null) if not userAttrsData: return False for attr in userAttrsData.keys(): if 'cgm' not in attr: attributes.doDeleteAttr(null, attr) guiFactory.warning("Deleted: '%s.%s'" % (null, attr))
def doPurgeNull(null): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Delete all non 'cgm' type user attributes on an object ARGUMENTS: moduleNull(string) RETURNS: infoNullDict(dict) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ userAttrsData = attributes.returnUserAttrsToDict(null) if not userAttrsData: return False for attr in userAttrsData.keys(): if 'cgm' not in attr: attributes.doDeleteAttr(null,attr) guiFactory.warning("Deleted: '%s.%s'"%(null,attr))
def purgeCGMAttrsFromObject(obj): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Delete all 'cgm' type user attributes on an object ARGUMENTS: moduleNull(string) RETURNS: infoNullDict(dict) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ userAttrsData = attributes.returnUserAttrsToList(obj) attrsToPurge = lists.returnMatchedIndexEntries(userAttrsData, 'cgm') if len(attrsToPurge): for attr in attrsToPurge: attributes.doDeleteAttr(obj, attr[0]) guiFactory.warning("Deleted: '%s.%s'" % (obj, attr[0])) return True else: return False
def purgeCGMAttrsFromObject(obj): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Delete all 'cgm' type user attributes on an object ARGUMENTS: moduleNull(string) RETURNS: infoNullDict(dict) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ userAttrsData = attributes.returnUserAttrsToList(obj) attrsToPurge = lists.returnMatchedIndexEntries(userAttrsData,'cgm') if len(attrsToPurge): for attr in attrsToPurge: attributes.doDeleteAttr(obj,attr[0]) guiFactory.warning("Deleted: '%s.%s'"%(obj,attr[0])) return True else: return False
def doSetType(self,setType = None): """ Set a set's type """ assert not self.refState, "Cannot change the type of a referenced set" assert not self.mayaSetState, "Cannot change type of a maya default set" if setType is not None: doSetType = setType if setType in setTypes.keys(): doSetType = setTypes.get(setType) if attributes.storeInfo(self.nameLong,'cgmType',doSetType,True): self.doName() guiFactory.warning("'%s' renamed!"%(self.nameShort)) return self.nameShort else: guiFactory.warning("'%s' failed to store info"%(self.nameShort)) return False else: attributes.doDeleteAttr(self.nameShort,'cgmType') self.doName() guiFactory.warning("'%s' renamed!"%(self.nameShort)) return self.nameShort
def doSetType(self, setType=None): """ Set a set's type """ assert not self.refState, "Cannot change the type of a referenced set" assert not self.mayaSetState, "Cannot change type of a maya default set" if setType is not None: doSetType = setType if setType in setTypes.keys(): doSetType = setTypes.get(setType) if attributes.storeInfo(self.nameLong, 'cgmType', doSetType, True): self.doName() guiFactory.warning("'%s' renamed!" % (self.nameShort)) return self.nameShort else: guiFactory.warning("'%s' failed to store info" % (self.nameShort)) return False else: attributes.doDeleteAttr(self.nameShort, 'cgmType') self.doName() guiFactory.warning("'%s' renamed!" % (self.nameShort)) return self.nameShort
def skeletonize(moduleNull, stiffIndex=0): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Basic limb skeletonizer ARGUMENTS: moduleNull(string) stiffIndex(int) - the index of the template objects you want to not have roll joints For example, a value of -1 will let the chest portion of a spine segment be solid instead of having a roll segment. Default is '0' which will put roll joints in every segment RETURNS: limbJoints(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>>Get our info #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> partName = NameFactory.returnUniqueGeneratedName(moduleNull, ignore='cgmType') """ template null """ templateNull = modules.returnTemplateNull(moduleNull) templateNullData = attributes.returnUserAttrsToDict(templateNull) """ template object nulls """ templatePosObjectsInfoNull = modules.returnInfoTypeNull( moduleNull, 'templatePosObjects') templateControlObjectsNull = modules.returnInfoTypeNull( moduleNull, 'templateControlObjects') templatePosObjectsInfoData = attributes.returnUserAttrsToDict( templatePosObjectsInfoNull) templateControlObjectsData = attributes.returnUserAttrsToDict( templateControlObjectsNull) jointOrientation = modules.returnSettingsData('jointOrientation') moduleRootBuffer = modules.returnInfoNullObjects(moduleNull, 'templatePosObjects', types='templateRoot') moduleRoot = moduleRootBuffer[0] stiffIndex = templateNullData.get('stiffIndex') rollJoints = templateNullData.get('rollJoints') """ AutonameStuff """ divider = NameFactory.returnCGMDivider() skinJointsNull = modules.returnInfoTypeNull(moduleNull, 'skinJoints') templateObjects = [] coreNamesArray = [] #>>>TemplateInfo for key in templatePosObjectsInfoData.keys(): if (mc.attributeQuery(key, node=templatePosObjectsInfoNull, msg=True)) == True: templateObjects.append(templatePosObjectsInfoData[key]) coreNamesArray.append(key) posTemplateObjects = [] """ Get the positional template objects""" for obj in templateObjects: bufferList = obj.split(divider) if (typesDictionary.get('templateObject')) in bufferList: posTemplateObjects.append(obj + divider + typesDictionary.get('locator')) """put objects in order of closeness to root""" posTemplateObjects = distance.returnDistanceSortedList( moduleRoot, posTemplateObjects) curve = (templatePosObjectsInfoData['curve']) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Actually making the skeleton with consideration for roll joints and the stiffIndex! #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> if stiffIndex == 0: """ If no roll joints """ limbJoints = joints.createJointsFromCurve(curve, partName, rollJoints) else: rolledJoints = joints.createJointsFromCurve(curve, partName, rollJoints) if rollJoints == 0: limbJoints = rolledJoints else: if stiffIndex < 0: """ Get our to delete number in a rolledJoints[-4:] format""" #searchIndex = (int('%s%s' %('-',(rollJoints+1)))*abs(stiffIndex)-1) searchIndex = (int('%s%s' % ('-', (rollJoints + 1))) * abs(stiffIndex)) toDelete = rolledJoints[searchIndex:] """ delete out the roll joints we don't want""" mc.delete(toDelete[0]) for name in toDelete: rolledJoints.remove(name) """ make our stiff joints """ jointPositions = [] if abs(stiffIndex) == 1: jointPositions.append( distance.returnClosestUPosition( posTemplateObjects[stiffIndex], curve)) else: for obj in posTemplateObjects[stiffIndex:]: jointPositions.append( distance.returnClosestUPosition(obj, curve)) stiffJoints = joints.createJointsFromPosListName( jointPositions, 'partName') """ connect em up """ mc.parent(stiffJoints[0], rolledJoints[-1]) limbJoints = [] for joint in rolledJoints: limbJoints.append(joint) for joint in stiffJoints: limbJoints.append(joint) else: """ if it's not negative, it's positive....""" searchIndex = ((rollJoints + 1) * abs(stiffIndex)) toDelete = rolledJoints[:searchIndex] toKeep = rolledJoints[searchIndex:] """ delete out the roll joints we don't want""" mc.parent(toKeep[0], world=True) mc.delete(toDelete[0]) for name in toDelete: rolledJoints.remove(name) """ make our stiff joints """ jointPositions = [] if abs(stiffIndex) == 1: jointPositions.append( distance.returnClosestUPosition( posTemplateObjects[stiffIndex - 1], curve)) else: for obj in posTemplateObjects[:stiffIndex]: jointPositions.append( distance.returnClosestUPosition(obj, curve)) stiffJoints = joints.createJointsFromPosListName( jointPositions, 'partName') """ connect em up """ mc.parent(rolledJoints[0], stiffJoints[-1]) limbJoints = [] for joint in stiffJoints: limbJoints.append(joint) for joint in rolledJoints: limbJoints.append(joint) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Naming #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ Copy naming information from template objects to the joints closest to them copy over a cgmNameModifier tag from the module first """ attributes.copyUserAttrs(moduleNull, limbJoints[0], attrsToCopy=['cgmNameModifier']) """ First we need to find our matches """ for obj in posTemplateObjects: closestJoint = distance.returnClosestObject(obj, limbJoints) transferObj = attributes.returnMessageObject(obj, 'cgmName') """Then we copy it""" attributes.copyUserAttrs( transferObj, closestJoint, attrsToCopy=['cgmNameModifier', 'cgmDirection', 'cgmName']) limbJointsBuffer = NameFactory.doRenameHeir(limbJoints[0]) limbJoints = [] limbJoints.append(limbJointsBuffer[0]) for joint in limbJointsBuffer[1]: limbJoints.append(joint) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Orientation #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> limbJoints = orientSegment(limbJoints, posTemplateObjects, jointOrientation) #>>> Set its radius and toggle axis visbility on #averageDistance = distance.returnAverageDistanceBetweenObjects (limbJoints) jointSize = ( distance.returnDistanceBetweenObjects(limbJoints[0], limbJoints[-1]) / 6) for jnt in limbJoints: mc.setAttr((jnt + '.radi'), jointSize * .2) #>>>>>>> TEMP joints.toggleJntLocalAxisDisplay(jnt) print 'to orientation' #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Storing data #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> skinJointsNull = modules.returnInfoTypeNull(moduleNull, 'skinJoints') skinJointsNullData = attributes.returnUserAttrsToList(skinJointsNull) existingSkinJoints = lists.removeMatchedIndexEntries( skinJointsNullData, 'cgm') print existingSkinJoints if len(existingSkinJoints) > 0: for entry in existingSkinJoints: attrBuffer = (skinJointsNull + '.' + entry[0]) print attrBuffer attributes.doDeleteAttr(skinJointsNull, entry[0]) for i in range(len(limbJoints)): buffer = ('%s%s' % ('joint_', i)) attributes.storeInfo(skinJointsNull, buffer, limbJoints[i]) return limbJoints