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 returnOrderedModules(masterNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Reads all of the modules attached to a masterNull and orders them by moduleParent heirarchy ARGUMENTS: masterNull(string) RETURNS: orderedModules(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ modules = returnSceneModules() moduleParents = {} for module in modules: moduleParents[module] = attributes.returnMessageObject( module, 'moduleParent') orderedModules = [] for key in moduleParents.keys(): if moduleParents.get(key) == masterNull: orderedModules.append(key) moduleParents.pop(key) while len(moduleParents) > 0: for module in orderedModules: for key in moduleParents.keys(): if moduleParents.get(key) == module: orderedModules.append(key) moduleParents.pop(key) return orderedModules
def returnOrderedModules(masterNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Reads all of the modules attached to a masterNull and orders them by moduleParent heirarchy ARGUMENTS: masterNull(string) RETURNS: orderedModules(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ modules = returnSceneModules() moduleParents ={} for module in modules: moduleParents[module] = attributes.returnMessageObject(module,'moduleParent') orderedModules = [] for key in moduleParents.keys(): if moduleParents.get(key) == masterNull: orderedModules.append(key) moduleParents.pop(key) while len(moduleParents)>0: for module in orderedModules: for key in moduleParents.keys(): if moduleParents.get(key) == module: orderedModules.append(key) moduleParents.pop(key) return orderedModules
def returnTagInfo(obj,tag): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Reads the data from a tag ARGUMENTS: obj(string) - object to read the tag from tag(string) - cgmName, cgmType, etc RETURNS: Success - read data Failure - false >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ if (mc.objExists('%s.%s' %(obj,tag))) == True: messageQuery = (mc.attributeQuery (tag,node=obj,msg=True)) if messageQuery == True: return attributes.returnMessageObject(obj,tag) else: infoBuffer = mc.getAttr('%s.%s' % (obj,tag)) if len(list(infoBuffer)) > 0: return infoBuffer else: return False else: return False
def returnInfoTypeNull(masterNull,infoType): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns an info null from a masterNull ARGUMENTS: masterNull(string) infoType(string) RETURNS: infoNull(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ masterInfoNull = attributes.returnMessageObject(masterNull,'info') infoNull = attributes.returnMessageObject(masterInfoNull,infoType) return infoNull
def getNameLinkObject(self): self.isObjectNameLinked = False if self.objGeneratedNameDict: if 'cgmName' in self.objGeneratedNameDict.keys(): if mc.objExists('%s.cgmName'%self.nameLong) and mc.attributeQuery ('cgmName',node=self.nameLong,msg=True): buffer = attributes.returnMessageObject(self.nameLong,'cgmName') self.nameLinkObject = buffer self.isObjectNameLinked = True
def getNameLinkObject(self): self.isObjectNameLinked = False if self.objGeneratedNameDict: if 'cgmName' in self.objGeneratedNameDict.keys(): if attributes.queryIfMessage(self.nameLong,'cgmName'): buffer = attributes.returnMessageObject(self.nameLong,'cgmName') self.nameLinkObject = buffer self.isObjectNameLinked = True
def returnInfoTypeNull(masterNull, infoType): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns an info null from a masterNull ARGUMENTS: masterNull(string) infoType(string) RETURNS: infoNull(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ masterInfoNull = attributes.returnMessageObject(masterNull, 'info') infoNull = attributes.returnMessageObject(masterInfoNull, infoType) return infoNull
def getNameLinkObject(self): self.isObjectNameLinked = False if self.objGeneratedNameDict: if 'cgmName' in self.objGeneratedNameDict.keys(): if attributes.queryIfMessage(self.nameLong, 'cgmName'): buffer = attributes.returnMessageObject( self.nameLong, 'cgmName') self.nameLinkObject = buffer self.isObjectNameLinked = True
def returnOrderedParentModules(masterNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns ordered list of modules connected to a master that have children ARGUMENTS: masterNull(string) RETURNS: orderedModules(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ modules = returnSceneModules() moduleParents = {} for module in modules: moduleParents[module] = attributes.returnMessageObject( module, 'moduleParent') moduleChildren = {} for module in modules: childrenBuffer = [] for checkModule in modules: if attributes.returnMessageObject(checkModule, 'moduleParent') == module: childrenBuffer.append(checkModule) if len(childrenBuffer) > 0: moduleChildren[module] = childrenBuffer orderedModules = [] for key in moduleChildren.keys(): if moduleParents.get(key) == masterNull: orderedModules.append(key) moduleChildren.pop(key) """ parse out the parent modules through the remaning modules""" while len(moduleChildren) > 0: for module in orderedModules: for key in moduleChildren.keys(): if moduleParents.get(key) == module: orderedModules.append(key) moduleChildren.pop(key) return orderedModules
def returnOrderedParentModules(masterNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns ordered list of modules connected to a master that have children ARGUMENTS: masterNull(string) RETURNS: orderedModules(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ modules = returnSceneModules() moduleParents ={} for module in modules: moduleParents[module] = attributes.returnMessageObject(module,'moduleParent') moduleChildren ={} for module in modules: childrenBuffer = [] for checkModule in modules: if attributes.returnMessageObject(checkModule,'moduleParent') == module: childrenBuffer.append(checkModule) if len(childrenBuffer) > 0: moduleChildren[module] = childrenBuffer orderedModules = [] for key in moduleChildren.keys(): if moduleParents.get(key) == masterNull: orderedModules.append(key) moduleChildren.pop(key) """ parse out the parent modules through the remaning modules""" while len(moduleChildren)>0: for module in orderedModules: for key in moduleChildren.keys(): if moduleParents.get(key) == module: orderedModules.append(key) moduleChildren.pop(key) return orderedModules
def verifyTemplateSizeObject(self, create=False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns an existing template size object or makes one and returns it ARGUMENTS: masterNull(list) RETURNS: returnList(list) - size object controls >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ templateSizeObject = attributes.returnMessageObject( self.PuppetNull.nameShort, 'templateSizeObject') if not mc.objExists(templateSizeObject) and create: self.createSizeTemplateControl() guiFactory.report("'%s' has template object '%s'" % (self.PuppetNull.nameShort, templateSizeObject)) return True elif templateSizeObject: self.templateSizeObjects['root'] = templateSizeObject self.templateSizeObjects['start'] = attributes.returnMessageObject( templateSizeObject, 'controlStart') self.templateSizeObjects['end'] = attributes.returnMessageObject( templateSizeObject, 'controlEnd') for key in self.templateSizeObjects.keys(): if not self.templateSizeObjects[key]: #self.templateSizeObjects = {} guiFactory.warning( "'%s' didn't check out. Rebuildling..." % (key)) try: mc.delete(templateSizeObject) self.createSizeTemplateControl() except: guiFactory.warning("Rebuild failed") return False guiFactory.report("'%s' has template object '%s'" % (self.PuppetNull.nameShort, templateSizeObject)) return True guiFactory.warning("Size template failed to verify") return False
def getNameLinkObject(self): self.isObjectNameLinked = False if self.objGeneratedNameDict: if 'cgmName' in self.objGeneratedNameDict.keys(): if mc.objExists( '%s.cgmName' % self.nameLong) and mc.attributeQuery( 'cgmName', node=self.nameLong, msg=True): buffer = attributes.returnMessageObject( self.nameLong, 'cgmName') self.nameLinkObject = buffer self.isObjectNameLinked = True
def doRenameHeir(obj, sceneUnique=False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Names an object's heirarchy below ARGUMENTS: obj(string) - the object we'd like to startfrom RETURNS: newNames(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ ### input check assert mc.objExists(obj) is True, "'%s' doesn't exist" % obj #children = mc.listRelatives(obj,allDescendents=True,type='transform') # Create a tmp group to store out objects to so that we can get them back even if heirarchal names change tmpGroup = mc.group(em=True) attributes.storeInfo(tmpGroup, ('name' + str(0)), obj) newNames = [] childrenList = [] children = mc.listRelatives(obj, allDescendents=True, fullPath=True) children.reverse() cnt = 1 for c in children: attributes.storeInfo(tmpGroup, ('name' + str(cnt)), c) cnt += 1 toNameAttrs = attributes.returnUserAttributes(tmpGroup) mayaMainProgressBar = guiFactory.doStartMayaProgressBar( len(toNameAttrs), 'Naming') for attr in toNameAttrs: if mc.progressBar(mayaMainProgressBar, query=True, isCancelled=True): break objectToName = (attributes.returnMessageObject(tmpGroup, attr)) mc.progressBar(mayaMainProgressBar, edit=True, status=("Naming '%s'" % objectToName), step=1) buffer = doNameObject(objectToName, sceneUnique) if buffer: newNames.append(buffer) guiFactory.doEndMayaProgressBar(mayaMainProgressBar) mc.delete(tmpGroup) return newNames
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 doRenameHeir(obj,sceneUnique = False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Names an object's heirarchy below ARGUMENTS: obj(string) - the object we'd like to startfrom RETURNS: newNames(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ ### input check assert mc.objExists(obj) is True, "'%s' doesn't exist" %obj #children = mc.listRelatives(obj,allDescendents=True,type='transform') # Create a tmp group to store out objects to so that we can get them back even if heirarchal names change tmpGroup = mc.group(em=True) attributes.storeInfo(tmpGroup,('name'+str(0)),obj) newNames = [] childrenList = [] children = mc.listRelatives(obj,allDescendents=True,fullPath=True) children.reverse() cnt = 1 for c in children: attributes.storeInfo(tmpGroup,('name'+str(cnt)),c) cnt += 1 toNameAttrs = attributes.returnUserAttributes(tmpGroup) mayaMainProgressBar = guiFactory.doStartMayaProgressBar(len(toNameAttrs),'Naming') for attr in toNameAttrs: if mc.progressBar(mayaMainProgressBar, query=True, isCancelled=True ) : break objectToName = (attributes.returnMessageObject(tmpGroup,attr)) mc.progressBar(mayaMainProgressBar, edit=True, status = ("Naming '%s'"%objectToName), step=1) buffer = doNameObject( objectToName,sceneUnique ) if buffer: newNames.append(buffer) guiFactory.doEndMayaProgressBar(mayaMainProgressBar) mc.delete(tmpGroup) return newNames
def returnTemplateNull(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns the template null of a module ARGUMENTS: moduleNull(string) RETURNS: templateNull(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ return (attributes.returnMessageObject(moduleNull, 'templateNull'))
def returnTemplateNull(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns the template null of a module ARGUMENTS: moduleNull(string) RETURNS: templateNull(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ return (attributes.returnMessageObject(moduleNull,'templateNull'))
def skeletonizeCharacter(masterNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Skeletonizes a character ARGUMENTS: masterNull(string) RETURNS: nothin >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ modules = modules.returnModules(masterNull) orderedModules = modules.returnOrderedModules(modules) #>>> Do the spine first stateCheck = modules.moduleStateCheck(orderedModules[0], ['template']) if stateCheck == 1: spineJoints = skeletonize(orderedModules[0]) else: print('%s%s' % (module, ' has already been skeletonized. Moving on...')) #>>> Do the rest for module in orderedModules[1:]: stateCheck = modules.moduleStateCheck(module, ['template']) if stateCheck == 1: templateNull = modules.returnTemplateNull(module) root = modules.returnInfoNullObjects(module, 'templatePosObjects', types='templateRoot') #>>> See if our item has a non default anchor anchored = storeTemplateRootParent(module) if anchored == True: anchor = attributes.returnMessageObject( root[0], 'skeletonParent') closestJoint = distance.returnClosestObject( anchor, spineJoints) else: closestJoint = distance.returnClosestObject( root[0], spineJoints) limbJoints = skeletonize(module) rootName = rigging.doParentReturnName(limbJoints[0], closestJoint) print rootName else: print('%s%s' % (module, ' has already been skeletonized. Moving on...'))
def returnInfoNullsFromModule(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns all info nulls of a module as a dictionary ARGUMENTS: moduleNull(string) RETURNS: infoNullDict(dict) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ moduleInfoNull = attributes.returnMessageObject(moduleNull, 'info') return attributes.returnUserAttrsToDict(moduleInfoNull)
def returnInfoNullsFromModule(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns all info nulls of a module as a dictionary ARGUMENTS: moduleNull(string) RETURNS: infoNullDict(dict) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ moduleInfoNull = attributes.returnMessageObject(moduleNull,'info') return attributes.returnUserAttrsToDict(moduleInfoNull)
def get(self,*a, **kw): """ Get and store attribute value based on attr type Keyword arguments: *a, **kw """ try: if self.form == 'message': self.value = attributes.returnMessageObject(self.obj.nameShort,self.attr) else: self.value = attributes.doGetAttr(self.obj.nameShort,self.attr) #guiFactory.report("'%s.%s' >> '%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 returnModules(masterNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns all the modules connected to a master null ARGUMENTS: masterNull(string) RETURNS: modules(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ modulesNull = returnInfoTypeNull(masterNull,'modules') moduleNames = attributes.returnMessageAttrs(modulesNull) modules = [] for module in moduleNames: modules.append(attributes.returnMessageObject(modulesNull,module)) return modules
def returnModules(masterNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns all the modules connected to a master null ARGUMENTS: masterNull(string) RETURNS: modules(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ modulesNull = returnInfoTypeNull(masterNull, 'modules') moduleNames = attributes.returnMessageAttrs(modulesNull) modules = [] for module in moduleNames: modules.append(attributes.returnMessageObject(modulesNull, module)) return modules
def get(self, *a, **kw): """ Get and store attribute value based on attr type Keyword arguments: *a, **kw """ try: if self.form == 'message': self.value = attributes.returnMessageObject( self.obj.nameShort, self.attr) else: self.value = attributes.doGetAttr(self.obj.nameShort, self.attr) #guiFactory.report("'%s.%s' >> '%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 returnObjectsOwnedByModuleNull(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns all objeccts owned by a particular module ARGUMENTS: moduleNull(string) for example the templateNull RETURNS: objList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ transformsList = mc.ls(tr=True) returnList = [] for obj in transformsList: userAttrsBuffer = attributes.returnUserAttributes(obj) if userAttrsBuffer > 0: for attr in userAttrsBuffer: if attr == 'cgmOwnedBy': messageObject = attributes.returnMessageObject(obj,attr) if messageObject == moduleNull: returnList.append(obj) return returnList
def returnOrderedChildrenModules(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns children parts organized by part type and direction ARGUMENTS: moduleNull(string) RETURNS: returnDict(dict) - {type:{direction:['1','2' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ modules = returnSceneModules() #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Info gathering #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> moduleParents ={} for module in modules: moduleParents[module] = attributes.returnMessageObject(module,'moduleParent') print moduleParents #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Parsing out Children #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> childrenModules = [] """ first we're gonna find all modules that have our module as it's parent""" for key in moduleParents.keys(): if moduleParents.get(key) == moduleNull: childrenModules.append(key) print childrenModules #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Further parsing #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> moduleTypes = {} typesPresent = [] """ first get the types and a simplified types present list """ for module in childrenModules: isType = search.returnTagInfo(module,'cgmModuleType') typesPresent.append(isType) moduleTypes[module] = isType typesPresent = lists.returnListNoDuplicates(typesPresent) """ get the data together for return """ moduleDirectionalInfo = {} directionsPresent = [] for module in childrenModules: isDirection = returnDirectionalInfoToString(module) directionsPresent.append(isDirection) moduleDirectionalInfo[module] = isDirection directionsPresent = lists.returnListNoDuplicates(directionsPresent) returnDict = {} for t in typesPresent: tagBuffer = {} for d in directionsPresent: dBuffer = [] for module in childrenModules: if moduleTypes.get(module) == t: if moduleDirectionalInfo.get(module) == d: dBuffer.append(module) if len(dBuffer) > 0: tagBuffer[d] = dBuffer returnDict[t] = tagBuffer if len(returnDict) > 0: return returnDict else: return False
def getInitialSize(self,PuppetInstance,*a,**kw): """ Class specific sizer. Keyword arguments: PuppetInstance(instance) -- should be the module's puppet instance """ guiFactory.report("Sizing via Limb - '%s'"%self.ModuleNull.nameBase) #>>> If it's a root if not self.moduleParent: guiFactory.report("Root module mode!") #>>>Get some info locInfoBuffer = ModuleFactory.doCreateStartingPositionLoc(self,'innerChild',PuppetInstance.templateSizeObjects['start'],PuppetInstance.templateSizeObjects['end']) print locInfoBuffer baseDistance = ModuleFactory.getPartBaseDistance(self,PuppetInstance,locInfoBuffer[0]) print "buffer is '%s'"%baseDistance modulePosInfoBuffer = template.getGeneratedInitialPositionData(self, PuppetInstance,locInfoBuffer,baseDistance) if not modulePosInfoBuffer: guiFactory.warning("Failed to get a size return on '%s'"%m) return False #Store the necessary info back to the Puppet for children processes to have access to PuppetInstance.sizeCorePositionList[self.ModuleNull.nameBase] = modulePosInfoBuffer['positions'] PuppetInstance.sizeLocInfo[self.ModuleNull.nameBase] = modulePosInfoBuffer['locator'] return True try:pass################### Need to come back to do these...woot except: if self.afModuleTyp.value in ['arm','wing','tail']: locInfoBuffer = ModuleFactory.doCreateStartingPositionLoc(self,'innerChild',PuppetInstance.templateSizeObjects['start'],PuppetInstance.templateSizeObjects['end']) PuppetInstance.locInfoDict[m] = createStartingPositionLoc(m,modeDict.get(self.afModuleTyp.value),typeWorkingCurveDict.get(self.afModuleTyp.value),typeAimingCurveDict.get(self.afModuleTyp.value),cvDict.get(directionKey)) orderedModules.remove(m) checkList.pop(m) elif self.afModuleTyp.value == 'clavicle': locInfoBuffer[m] = createStartingPositionLoc(m,modeDict.get(self.afModuleTyp.value),templateSizeObjects[1],templateSizeObjects[0],cvDict.get(directionKey)) orderedModules.remove(m) checkList.pop(m) elif self.afModuleTyp.value == 'finger': moduleParent = attributes.returnMessageObject(m,'moduleParent') parentLoc = locInfo.get(moduleParent) locInfoBuffer[m] = createStartingPositionLoc(m,modeDict.get(self.afModuleTyp.value),parentLoc) orderedModules.remove(m) elif self.afModuleTyp.value == 'foot': moduleParent = attributes.returnMessageObject(m,'moduleParent') parentLoc = locInfo.get(moduleParent) locInfoBuffer[m] = createStartingPositionLoc(m,modeDict.get(self.afModuleTyp.value),parentLoc) orderedModules.remove(m) checkList.pop(m) elif self.afModuleTyp.value == 'head': locInfoBuffer[m] = createStartingPositionLoc(m,modeDict.get(self.afModuleTyp.value),templateSizeObjects[1],templateSizeObjects[0],cvDict.get(directionKey)) orderedModules.remove(m) checkList.pop(m) elif self.afModuleTyp.value == 'leg': if basicOrientation == 'vertical': locInfoBuffer[m] = createStartingPositionLoc(m,modeDict.get(self.afModuleTyp.value),typeWorkingCurveDict.get(self.afModuleTyp.value),typeAimingCurveDict.get(self.afModuleTyp.value),cvDict.get(directionKey)) else: horizontalLegInfoBuffer = horiztonalLegDict.get(directionKey) locInfoBuffer[m] = createStartingPositionLoc(m,modeDict.get(self.afModuleTyp.value),horizontalLegInfoBuffer[1],horizontalLegInfoBuffer[2],horizontalLegInfoBuffer[0])
def addOrientationHelpers(self): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Adds orientation helpers to a template chain ARGUMENTS: objects(list) root(string) - root control of the limb chain moduleType(string) RETURNS: returnList(list) = [rootHelper(string),helperObjects(list),helperObjectGroups(list)] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ moduleColors = modules.returnModuleColors(self.ModuleNull.nameLong) helperObjects = [] helperObjectGroups = [] returnBuffer = [] root = self.msgTemplateRoot.getMessage() visAttr = "%s.visOrientHelpers" % self.infoNulls['visibilityOptions'].get() objects = self.templatePosObjectsBuffer.bufferList #>>> Direction and size Stuff """ Directional data derived from joints """ generalDirection = logic.returnHorizontalOrVertical(objects) if generalDirection == 'vertical' and 'leg' not in self.afModuleType.get(): worldUpVector = [0, 0, -1] elif generalDirection == 'vertical' and 'leg' in self.afModuleType.get(): worldUpVector = [0, 0, 1] else: worldUpVector = [0, 1, 0] #Get Size size = (distance.returnBoundingBoxSizeToAverage(objects[0]) * 2) #>>> Master Orient helper createBuffer = curves.createControlCurve('circleArrow1', (size * 2), 'z+') # make the curve curves.setCurveColorByName(createBuffer, moduleColors[0]) attributes.storeInfo(createBuffer, 'cgmType', 'templateOrientRoot') #copy the name attr mainOrientHelperObj = NameFactory.doNameObject(createBuffer) attributes.storeObjectToMessage( mainOrientHelperObj, self.msgTemplateRoot.get(), 'orientHelper') #store the object to it's respective object returnBuffer.append(mainOrientHelperObj) # Snapping position.movePointSnap(mainOrientHelperObj, root) constBuffer = mc.aimConstraint(objects[1], mainOrientHelperObj, maintainOffset=False, weight=1, aimVector=[1, 0, 0], upVector=[0, 1, 0], worldUpVector=worldUpVector, worldUpType='vector') mc.delete(constBuffer[0]) # Follow Groups mainOrientHelperGroupBuffer = rigging.groupMeObject(mainOrientHelperObj) mainOrientHelperGroupBuffer = NameFactory.doNameObject( mainOrientHelperGroupBuffer) mainOrientHelperGroup = rigging.doParentReturnName( mainOrientHelperGroupBuffer, root) mc.pointConstraint(objects[0], mainOrientHelperGroupBuffer, maintainOffset=False) helperObjectGroups.append(mainOrientHelperGroup) # set up constraints mc.aimConstraint(objects[-1], mainOrientHelperGroup, maintainOffset=True, weight=1, aimVector=[1, 0, 0], upVector=[0, 1, 0], worldUpObject=root, worldUpType='objectRotation') # lock and hide stuff attributes.doSetLockHideKeyableAttr( mainOrientHelperObj, True, False, False, ['tx', 'ty', 'tz', 'rz', 'ry', 'sx', 'sy', 'sz', 'v']) #>>> The sub helpers """ make our pair lists """ pairList = lists.parseListToPairs(objects) """ make our controls """ helperObjects = [] for pair in pairList: """ Get Size """ size = (distance.returnBoundingBoxSizeToAverage(pair[0]) * 2) """ make the curve""" createBuffer = curves.createControlCurve('circleArrow2Axis', size, 'y-') curves.setCurveColorByName(createBuffer, moduleColors[1]) """ copy the name attr""" attributes.copyUserAttrs(pair[0], createBuffer, ['cgmName']) attributes.storeInfo(createBuffer, 'cgmType', 'templateOrientObject') helperObj = NameFactory.doNameObject(createBuffer) """ store the object to it's respective object and to an object list """ attributes.storeObjectToMessage(helperObj, pair[0], 'orientHelper') helperObjects.append(helperObj) """ initial snapping """ position.movePointSnap(helperObj, pair[0]) constBuffer = mc.aimConstraint(pair[1], helperObj, maintainOffset=False, weight=1, aimVector=[1, 0, 0], upVector=[0, 1, 0], worldUpVector=worldUpVector, worldUpType='vector') mc.delete(constBuffer[0]) """ follow groups """ helperGroupBuffer = rigging.groupMeObject(helperObj) helperGroup = NameFactory.doNameObject(helperGroupBuffer) helperGroup = rigging.doParentReturnName(helperGroup, pair[0]) helperObjectGroups.append(helperGroup) """ set up constraints """ mc.aimConstraint(pair[1], helperGroup, maintainOffset=False, weight=1, aimVector=[1, 0, 0], upVector=[0, 1, 0], worldUpVector=[0, 1, 0], worldUpObject=mainOrientHelperObj, worldUpType='objectrotation') """ lock and hide stuff """ helperObj = attributes.returnMessageObject(pair[0], 'orientHelper') mc.connectAttr((visAttr), (helperObj + '.v')) attributes.doSetLockHideKeyableAttr( helperObj, True, False, False, ['tx', 'ty', 'tz', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) #>>> For the last object in the chain for obj in objects[-1:]: """ Get Size """ size = (distance.returnBoundingBoxSizeToAverage(obj) * 2) """ make the curve""" createBuffer = curves.createControlCurve('circleArrow2Axis', size, 'y-') curves.setCurveColorByName(createBuffer, moduleColors[1]) """ copy the name attr""" attributes.copyUserAttrs(obj, createBuffer, ['cgmName']) attributes.storeInfo(createBuffer, 'cgmType', 'templateOrientObject') helperObj = NameFactory.doNameObject(createBuffer) """ store the object to it's respective object """ attributes.storeObjectToMessage(helperObj, obj, 'orientHelper') """ initial snapping """ position.movePointSnap(helperObj, obj) constBuffer = mc.aimConstraint(objects[-2], helperObj, maintainOffset=False, weight=1, aimVector=[1, 0, 0], upVector=[0, 1, 0], worldUpVector=worldUpVector, worldUpType='vector') mc.delete(constBuffer[0]) """ follow groups """ helperGroupBuffer = rigging.groupMeObject(helperObj) helperGroup = NameFactory.doNameObject(helperGroupBuffer) helperGroup = rigging.doParentReturnName(helperGroup, obj) helperObjectGroups.append(helperGroup) """ set up constraints """ secondToLastHelperObject = attributes.returnMessageObject( objects[-2], 'orientHelper') mc.orientConstraint(secondToLastHelperObject, helperGroup, maintainOffset=False, weight=1) """ lock and hide stuff """ helperObj = attributes.returnMessageObject(obj, 'orientHelper') mc.connectAttr((visAttr), (helperObj + '.v')) attributes.doSetLockHideKeyableAttr( helperObj, True, False, False, ['tx', 'ty', 'tz', 'sx', 'sy', 'sz', 'v']) helperObjects.append(helperObj) returnBuffer.append(helperObjects) returnBuffer.append(helperObjectGroups) return returnBuffer
def saveTemplateToModule(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: * Save the new positional information from the template objects * Collect all names of objects for a delete list * If anything in the module doesn't belong there, un parent it, report it * like a template object parented to another obect ARGUMENTS: moduleNull(string) RETURNS: limbJoints(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Variables #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Get our base info """ module null data """ moduleNullData = attributes.returnUserAttrsToDict(moduleNull) """ part name """ partName = NameFactory.returnUniqueGeneratedName(moduleNull, ignore = 'cgmType') partType = moduleNullData.get('cgmModuleType') direction = moduleNullData.get('cgmDirection') """ template null """ templateNull = moduleNullData.get('templateNull') templateNullData = attributes.returnUserAttrsToDict(templateNull) """ template object nulls """ templatePosObjectsInfoNull = returnInfoTypeNull(moduleNull,'templatePosObjects') templatePosObjectsInfoData = attributes.returnUserAttrsToDict (templatePosObjectsInfoNull) templateControlObjectsNull = returnInfoTypeNull(moduleNull,'templateControlObjects') templateControlObjectsData = attributes.returnUserAttrsToDict (templateControlObjectsNull) """ rig null """ rigNull = moduleNullData.get('rigNull') """ Start objects stuff """ templateStarterDataInfoNull = returnInfoTypeNull(moduleNull,'templateStarterData') templateControlObjectsDataNull = returnInfoTypeNull(moduleNull,'templateControlObjectsData') """ AutonameStuff """ divider = NameFactory.returnCGMDivider() moduleRootBuffer = returnInfoNullObjects(moduleNull,'templatePosObjects',types='templateRoot') moduleRoot = moduleRootBuffer[0] 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) """ get our control template objects """ controlTemplateObjects=[] for key in templateControlObjectsData.keys(): if (mc.attributeQuery (key,node=templateControlObjectsNull,msg=True)) == True: controlTemplateObjects.append (templateControlObjectsData[key]) """put objects in order of closeness to root""" posTemplateObjects = distance.returnDistanceSortedList(moduleRoot,posTemplateObjects) controlTemplateObjects = distance.returnDistanceSortedList(moduleRoot,controlTemplateObjects) curve = (templatePosObjectsInfoData['curve']) #>>> get our orientation helpers helperObjects = [] for obj in posTemplateObjects: helperObjects.append(attributes.returnMessageObject(obj,'orientHelper')) masterOrient = (attributes.returnMessageObject(moduleRoot,'orientHelper')) print ('%s%s'% (moduleNull,' data acquired...')) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Save Data #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Get the data """ pos objects """ storageData = [] for obj in posTemplateObjects: storageData.append(mc.xform (obj, q=True, ws=True, sp=True)) """ orientation helpers """ for obj in helperObjects: storageData.append(mc.xform (obj, q=True, os=True, ro=True)) storageData.append(mc.xform (masterOrient, q=True, os=True, ro=True)) print storageData """ template control objects data""" tempateControlObjectsStorageData = [] for obj in controlTemplateObjects: print obj tempateControlObjectsStorageData.append(mc.xform (obj, q=True, ws=True, t=True)) tempateControlObjectsStorageData.append(mc.xform (obj, q=True, os=True, ro=True)) rootScale = (mc.xform (moduleRoot, q=True, relative = True, scale=True)) objScaleBuffer = (mc.xform (obj, q=True, relative = True, scale=True)) objScale = [] cnt = 0 for scale in objScaleBuffer: objScale.append(scale*rootScale[cnt]) cnt+=1 tempateControlObjectsStorageData.append(objScale) print tempateControlObjectsStorageData #>>> Store the data to the initial objects pos """ Get the attributes to store to""" initialObjectsTemplateDataBuffer = attributes.returnUserAttrsToList(templateStarterDataInfoNull) initialObjectsPosData = lists.removeMatchedIndexEntries(initialObjectsTemplateDataBuffer,'cgm') """ store it""" cnt=0 for set in initialObjectsPosData: attrBuffer = set[0] xBuffer = (templateStarterDataInfoNull+'.'+attrBuffer+'X') yBuffer = (templateStarterDataInfoNull+'.'+attrBuffer+'Y') zBuffer = (templateStarterDataInfoNull+'.'+attrBuffer+'Z') dataSet = storageData[cnt] mc.setAttr (xBuffer, dataSet[0]) mc.setAttr (yBuffer, dataSet[1]) mc.setAttr (zBuffer, dataSet[2]) cnt+=1 #>>> Store the data to the initial objects pos """ Get the attributes to store to""" templateControlObjectsDataNullBuffer = attributes.returnUserAttrsToList(templateControlObjectsDataNull) templateControlObjectsData = lists.removeMatchedIndexEntries(templateControlObjectsDataNullBuffer,'cgm') """ store it""" cnt=0 for set in templateControlObjectsData: attrBuffer = set[0] xBuffer = (templateControlObjectsDataNull+'.'+attrBuffer+'X') yBuffer = (templateControlObjectsDataNull+'.'+attrBuffer+'Y') zBuffer = (templateControlObjectsDataNull+'.'+attrBuffer+'Z') dataSet = tempateControlObjectsStorageData[cnt] mc.setAttr (xBuffer, dataSet[0]) mc.setAttr (yBuffer, dataSet[1]) mc.setAttr (zBuffer, dataSet[2]) cnt+=1 #>>>>>>need to add locking>>>>>>>>>>>>>>>>>>>>>>>>>>>> print ('%s%s'% (moduleNull,' template object positional/rotational/scale data stored...')) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Save skin joints to skin joints null #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Delete stuff #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ Gather our objects""" toDeleteList = search.returnObjectsOwnedByModuleNull(templateNull) print toDeleteList for obj in toDeleteList: if mc.objExists(obj) == True: print ('%s%s'% (obj,' deleted...')) mc.delete(obj) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Change Tag #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> mc.setAttr ((moduleNull+'.templateState'), 0) mc.setAttr ((moduleNull+'.skeletonState'), 1) #add locking print ('%s%s'% (moduleNull,' done')) return 'done'
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
def returnOrderedChildrenModules(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns children parts organized by part type and direction ARGUMENTS: moduleNull(string) RETURNS: returnDict(dict) - {type:{direction:['1','2' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ modules = returnSceneModules() #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Info gathering #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> moduleParents = {} for module in modules: moduleParents[module] = attributes.returnMessageObject( module, 'moduleParent') print moduleParents #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Parsing out Children #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> childrenModules = [] """ first we're gonna find all modules that have our module as it's parent""" for key in moduleParents.keys(): if moduleParents.get(key) == moduleNull: childrenModules.append(key) print childrenModules #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Further parsing #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> moduleTypes = {} typesPresent = [] """ first get the types and a simplified types present list """ for module in childrenModules: isType = search.returnTagInfo(module, 'cgmModuleType') typesPresent.append(isType) moduleTypes[module] = isType typesPresent = lists.returnListNoDuplicates(typesPresent) """ get the data together for return """ moduleDirectionalInfo = {} directionsPresent = [] for module in childrenModules: isDirection = returnDirectionalInfoToString(module) directionsPresent.append(isDirection) moduleDirectionalInfo[module] = isDirection directionsPresent = lists.returnListNoDuplicates(directionsPresent) returnDict = {} for t in typesPresent: tagBuffer = {} for d in directionsPresent: dBuffer = [] for module in childrenModules: if moduleTypes.get(module) == t: if moduleDirectionalInfo.get(module) == d: dBuffer.append(module) if len(dBuffer) > 0: tagBuffer[d] = dBuffer returnDict[t] = tagBuffer if len(returnDict) > 0: return returnDict else: return False
def orientSegment(limbJoints, posTemplateObjects, orientation): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Basic limb skeletonizer ARGUMENTS: limbJoints(list) templeateObjects(list) orientation(string) - ['xyz','yzx','zxy','xzy','yxz','zyx'] RETURNS: limbJoints(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ """ orientation vectors""" orientationVectors = search.returnAimUpOutVectorsFromOrientation( orientation) wantedAimVector = orientationVectors[0] wantedUpVector = orientationVectors[1] """put objects in order of closeness to root""" limbJoints = distance.returnDistanceSortedList(limbJoints[0], limbJoints) #>>> Segment our joint list by names jointSegmentsList = [] cullList = [] """ gonna be culling items from the list so need to rebuild it, just doing a list1 = list2 somehow keeps the relationship....odd """ for obj in limbJoints: cullList.append(obj) while len(cullList) > 0: matchTerm = search.returnTagInfo(cullList[0], 'cgmName') objSet = search.returnMatchedTagsFromObjectList( cullList, 'cgmName', matchTerm) jointSegmentsList.append(objSet) for obj in objSet: cullList.remove(obj) #>>> get our orientation helpers helperObjects = [] for obj in posTemplateObjects: templateObj = attributes.returnMessageObject(obj, 'cgmName') helperObjects.append( attributes.returnMessageObject(templateObj, 'orientHelper')) #>>> un parenting the chain for joint in limbJoints[1:]: mc.parent(joint, world=True) #>>>per segment stuff cnt = 0 for segment in jointSegmentsList: if len(segment) > 1: """ creat our up object from from the helper object """ helperObjectCurvesShapes = mc.listRelatives(helperObjects[cnt], shapes=True) upLoc = locators.locMeCvFromCvIndex(helperObjectCurvesShapes[0], 30) print upLoc """ make a pair list""" pairList = lists.parseListToPairs(segment) for pair in pairList: """ set up constraints """ constraintBuffer = mc.aimConstraint(pair[1], pair[0], maintainOffset=False, weight=1, aimVector=wantedAimVector, upVector=wantedUpVector, worldUpVector=[0, 1, 0], worldUpObject=upLoc, worldUpType='object') mc.delete(constraintBuffer[0]) for obj in segment[-1:]: constraintBuffer = mc.orientConstraint(segment[-2], obj, maintainOffset=False, weight=1) mc.delete(constraintBuffer[0]) """ increment and delete the up loc """ cnt += 1 mc.delete(upLoc) else: helperObjectCurvesShapes = mc.listRelatives(helperObjects[cnt], shapes=True) upLoc = locators.locMeCvFromCvIndex(helperObjectCurvesShapes[0], 30) """ make an aim object """ aimLoc = locators.locMeObject(helperObjects[cnt]) aimLocGroup = rigging.groupMeObject(aimLoc) mc.move(10, 0, 0, aimLoc, localSpace=True) constraintBuffer = mc.aimConstraint(aimLoc, segment[0], maintainOffset=False, weight=1, aimVector=wantedAimVector, upVector=wantedUpVector, worldUpVector=[0, 1, 0], worldUpObject=upLoc, worldUpType='object') mc.delete(constraintBuffer[0]) mc.delete(aimLocGroup) mc.delete(upLoc) cnt += 1 #>>>reconnect the joints pairList = lists.parseListToPairs(limbJoints) for pair in pairList: mc.parent(pair[1], pair[0]) """ Freeze the rotations """ mc.makeIdentity(limbJoints[0], apply=True, r=True) return limbJoints
def saveTemplateToModule(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: * Save the new positional information from the template objects * Collect all names of objects for a delete list * If anything in the module doesn't belong there, un parent it, report it * like a template object parented to another obect ARGUMENTS: moduleNull(string) RETURNS: limbJoints(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Variables #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Get our base info """ module null data """ moduleNullData = attributes.returnUserAttrsToDict(moduleNull) """ part name """ partName = NameFactory.returnUniqueGeneratedName(moduleNull, ignore='cgmType') partType = moduleNullData.get('cgmModuleType') direction = moduleNullData.get('cgmDirection') """ template null """ templateNull = moduleNullData.get('templateNull') templateNullData = attributes.returnUserAttrsToDict(templateNull) """ template object nulls """ templatePosObjectsInfoNull = returnInfoTypeNull(moduleNull, 'templatePosObjects') templatePosObjectsInfoData = attributes.returnUserAttrsToDict( templatePosObjectsInfoNull) templateControlObjectsNull = returnInfoTypeNull(moduleNull, 'templateControlObjects') templateControlObjectsData = attributes.returnUserAttrsToDict( templateControlObjectsNull) """ rig null """ rigNull = moduleNullData.get('rigNull') """ Start objects stuff """ templateStarterDataInfoNull = returnInfoTypeNull(moduleNull, 'templateStarterData') templateControlObjectsDataNull = returnInfoTypeNull( moduleNull, 'templateControlObjectsData') """ AutonameStuff """ divider = NameFactory.returnCGMDivider() moduleRootBuffer = returnInfoNullObjects(moduleNull, 'templatePosObjects', types='templateRoot') moduleRoot = moduleRootBuffer[0] 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) """ get our control template objects """ controlTemplateObjects = [] for key in templateControlObjectsData.keys(): if (mc.attributeQuery(key, node=templateControlObjectsNull, msg=True)) == True: controlTemplateObjects.append(templateControlObjectsData[key]) """put objects in order of closeness to root""" posTemplateObjects = distance.returnDistanceSortedList( moduleRoot, posTemplateObjects) controlTemplateObjects = distance.returnDistanceSortedList( moduleRoot, controlTemplateObjects) curve = (templatePosObjectsInfoData['curve']) #>>> get our orientation helpers helperObjects = [] for obj in posTemplateObjects: helperObjects.append( attributes.returnMessageObject(obj, 'orientHelper')) masterOrient = (attributes.returnMessageObject(moduleRoot, 'orientHelper')) print('%s%s' % (moduleNull, ' data acquired...')) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Save Data #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Get the data """ pos objects """ storageData = [] for obj in posTemplateObjects: storageData.append(mc.xform(obj, q=True, ws=True, sp=True)) """ orientation helpers """ for obj in helperObjects: storageData.append(mc.xform(obj, q=True, os=True, ro=True)) storageData.append(mc.xform(masterOrient, q=True, os=True, ro=True)) print storageData """ template control objects data""" tempateControlObjectsStorageData = [] for obj in controlTemplateObjects: print obj tempateControlObjectsStorageData.append( mc.xform(obj, q=True, ws=True, t=True)) tempateControlObjectsStorageData.append( mc.xform(obj, q=True, os=True, ro=True)) rootScale = (mc.xform(moduleRoot, q=True, relative=True, scale=True)) objScaleBuffer = (mc.xform(obj, q=True, relative=True, scale=True)) objScale = [] cnt = 0 for scale in objScaleBuffer: objScale.append(scale * rootScale[cnt]) cnt += 1 tempateControlObjectsStorageData.append(objScale) print tempateControlObjectsStorageData #>>> Store the data to the initial objects pos """ Get the attributes to store to""" initialObjectsTemplateDataBuffer = attributes.returnUserAttrsToList( templateStarterDataInfoNull) initialObjectsPosData = lists.removeMatchedIndexEntries( initialObjectsTemplateDataBuffer, 'cgm') """ store it""" cnt = 0 for set in initialObjectsPosData: attrBuffer = set[0] xBuffer = (templateStarterDataInfoNull + '.' + attrBuffer + 'X') yBuffer = (templateStarterDataInfoNull + '.' + attrBuffer + 'Y') zBuffer = (templateStarterDataInfoNull + '.' + attrBuffer + 'Z') dataSet = storageData[cnt] mc.setAttr(xBuffer, dataSet[0]) mc.setAttr(yBuffer, dataSet[1]) mc.setAttr(zBuffer, dataSet[2]) cnt += 1 #>>> Store the data to the initial objects pos """ Get the attributes to store to""" templateControlObjectsDataNullBuffer = attributes.returnUserAttrsToList( templateControlObjectsDataNull) templateControlObjectsData = lists.removeMatchedIndexEntries( templateControlObjectsDataNullBuffer, 'cgm') """ store it""" cnt = 0 for set in templateControlObjectsData: attrBuffer = set[0] xBuffer = (templateControlObjectsDataNull + '.' + attrBuffer + 'X') yBuffer = (templateControlObjectsDataNull + '.' + attrBuffer + 'Y') zBuffer = (templateControlObjectsDataNull + '.' + attrBuffer + 'Z') dataSet = tempateControlObjectsStorageData[cnt] mc.setAttr(xBuffer, dataSet[0]) mc.setAttr(yBuffer, dataSet[1]) mc.setAttr(zBuffer, dataSet[2]) cnt += 1 #>>>>>>need to add locking>>>>>>>>>>>>>>>>>>>>>>>>>>>> print('%s%s' % (moduleNull, ' template object positional/rotational/scale data stored...')) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Save skin joints to skin joints null #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Delete stuff #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ Gather our objects""" toDeleteList = search.returnObjectsOwnedByModuleNull(templateNull) print toDeleteList for obj in toDeleteList: if mc.objExists(obj) == True: print('%s%s' % (obj, ' deleted...')) mc.delete(obj) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Change Tag #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> mc.setAttr((moduleNull + '.templateState'), 0) mc.setAttr((moduleNull + '.skeletonState'), 1) #add locking print('%s%s' % (moduleNull, ' done')) return 'done'