def installModule(self, module, *arg): basename = 'instance_' cmds.namespace(setNamespace=":") namespaces = cmds.namespaceInfo(listOnlyNamespaces=True) for i in range(len(namespaces)): if namespaces[i].find('__') != -1: namespaces[i] = namespaces[i].partition('__')[2] newSuffix = utils.findHighestTrailingNumber(namespaces, basename) + 1 userSpecName = basename + str(newSuffix) hookObj = self.findHookObjectFromSelection() mod = __import__('Blueprint.'+ module,{},{},[module]) reload(mod) moduleClass = getattr(mod, mod.CLASS_NAME) moduleInstance = moduleClass(userSpecName, hookObj) moduleInstance.install() #this is to make sure move tool is selected by default moduleTransform = mod.CLASS_NAME + '__' + userSpecName + ':module_transform' cmds.select(moduleTransform, replace=True) cmds.setToolTo('moveSuperContext')
def resolveNamespaceClashes(self, tempNamespace): returnNames = [] cmds.namespace(setNamespace=tempNamespace) namespaces = cmds.namespaceInfo(listOnlyNamespaces=True) cmds.namespace(setNamespace=':') existingNamespaces = cmds.namespaceInfo(listOnlyNamespaces=True) for i in range(len(namespaces)): namespaces[i] = namespaces[i].partition(tempNamespace+ ':')[2] for name in namespaces: newName = str(name) oldName = tempNamespace + ':' + name if name in existingNamespaces: highestSuffix = utils.findHighestTrailingNumber(existingNamespaces, name+'_') highestSuffix += 1 newName = str(name) + '_' + str(highestSuffix) returnNames.append([oldName,newName]) self.resolveNameChangeMirrorLinks(returnNames,tempNamespace) self.renameNamespaces(returnNames) return returnNames
def resolveNamespaceClashes(self, tempNamespace): returnNames = [] cmds.namespace(setNamespace=tempNamespace) namespaces = cmds.namespaceInfo(listOnlyNamespaces=True) cmds.namespace(setNamespace=":") existingNamespaces = cmds.namespaceInfo(listOnlyNamespaces=True) for i in range(len(namespaces)): namespaces[i] = namespaces[i].partition(tempNamespace+":")[2] for name in namespaces: newName = str(name) oldName = tempNamespace + ":" + name if name in existingNamespaces: highestSuffix = utils.findHighestTrailingNumber(existingNamespaces, name+"_") highestSuffix += 1 newName = str(name) + "_" + str(highestSuffix) returnNames.append([oldName, newName]) self.resolveNameChangeMirrorLinks(returnNames, tempNamespace) self.renameNamespaces(returnNames) return returnNames
def installModule(self, module, *args): basename = "instance_" #set namespace equals to root cmds.namespace(setNamespace=":") namespaces = cmds.namespaceInfo(listOnlyNamespaces=True) # if any contains "__" we want to delete for i in range(len(namespaces)): #if found if namespaces[i].find("__") != -1: namespaces[i] = namespaces[i].partition("__")[2] newSuffix = utils.findHighestTrailingNumber(namespaces,basename) + 1 userSpecName = basename + str(newSuffix) hookObj = self.findHookObjectFromSelection() mod =__import__("Blueprint."+module,{},{}, [module]) reload(mod) moduleClass = getattr(mod, mod.CLASS_NAME) moduleInstance = moduleClass(userSpecName, hookObj) moduleInstance.install() #Select the module outline and Make move Tool ACTIVE moduleTransform = mod.CLASS_NAME + "__" + userSpecName + ":module_transform" cmds.select(moduleTransform, replace=True) cmds.setToolTo("moveSuperContext")
def getCharacterNamespace(characterName): baseNamespace = "Character__" + characterName + "_" extraNamespace = "Export__" + characterName + "_" cmds.namespace(setNamespace=":") namespaces=cmds.namespaceInfo(listOnlyNamespaces=True) highestSuffix = utils.findHighestTrailingNumber(namespaces, baseNamespace) highestSuffix += 1 characterNamespace = baseNamespace + str(highestSuffix) exportNamespace = extraNamespace + str(highestSuffix) return (characterNamespace, exportNamespace)
def getCharacterNamespace(characterName): baseNamespace = "Character__" + characterName + "_" extraNamespace = "Export__" + characterName + "_" cmds.namespace(setNamespace=":") namespaces = cmds.namespaceInfo(listOnlyNamespaces=True) highestSuffix = utils.findHighestTrailingNumber(namespaces, baseNamespace) highestSuffix += 1 characterNamespace = baseNamespace + str(highestSuffix) exportNamespace = extraNamespace + str(highestSuffix) return (characterNamespace, exportNamespace)
def resolveGroupNameClashes(self,tempNamespace): cmds.namespace(setNamespace = tempNamespace) dependencyNodes = cmds.namespaceInfo(listOnlyDependencyNodes=True) cmds.namespace(setNamespace=':') transforms = cmds.ls(dependencyNodes, transforms=True) groups = [] for node in transforms: if node.find(tempNamespace+':Group__') == 0: groups.append(node) if len(groups) == 0: return groups groupNames = [] for group in groups: groupName = group.partition(tempNamespace+':')[2] newGroupName = str(groupName) if cmds.objExists(newGroupName): existingGroups = cmds.ls('Group__*', transforms=True) highestSuffix = utils.findHighestTrailingNumber(existingGroups, groupName+'_') highestSuffix += 1 newGroupName = str(groupName) + '_' + str(highestSuffix) groupNames.append([group,newGroupName]) self.resolveNameChangeMirrorLinks(groupNames, tempNamespace) groupContainer = tempNamespace + ':Group_container' if cmds.objExists(groupContainer): cmds.lockNode(groupContainer, lock=False, lockUnpublished=False) for name in groupNames: cmds.rename(name[0], name[1]) if cmds.objExists(groupContainer): cmds.lockNode(groupContainer, lock=True, lockUnpublished=True) return groupNames
def installCharacter(self, *args): characterName = cmds.textScrollList(self.UIElements['characterlist'],q=True, selectItem=True)[0] characterFileName = os.environ['RIGGING_TOOL_ROOT'] + '/Characters/' + characterName + '.ma' baseNamespace = 'Character__' + characterName + '_' cmds.namespace(setNamespace=':') namespaces = cmds.namespaceInfo(listOnlyNamespaces=True) highestSuffix = utils.findHighestTrailingNumber(namespaces,baseNamespace) highestSuffix += 1 characterNamespace = baseNamespace + str(highestSuffix) cmds.file(characterFileName,i=True,namespace=characterNamespace) cmds.deleteUI(self.UIElements['window'])
def installCharacter(self, *args): characterName = cmds.textScrollList(self.UIElements["characterList"], q=True, selectItem=True)[0] characterFilename = os.environ[ "RIGGING_TOOL_ROOT"] + "/Characters/" + characterName + ".ma" baseNamespace = "Character__" + characterName + "_" cmds.namespace(setNamespace=":") namespaces = cmds.namespaceInfo(listOnlyNamespaces=True) highestSuffix = utils.findHighestTrailingNumber( namespaces, baseNamespace) highestSuffix += 1 characterNamespace = baseNamespace + str(highestSuffix) cmds.file(characterFilename, i=True, namespace=characterNamespace) cmds.deleteUI(self.UIElements["window"])
def resolveGroupNameClashes(self, tempNamespace): cmds.namespace(setNamespace = tempNamespace) dependencyNodes = cmds.namespaceInfo(listOnlyDependencyNodes=True) cmds.namespace(setNamespace=":") transforms = cmds.ls(dependencyNodes, transforms=True) groups = [] for node in transforms: if node.find(tempNamespace+":Group__") == 0: groups.append(node) if len(groups) == 0: return groups groupNames = [] for group in groups: groupName = group.partition(tempNamespace+":")[2] newGroupName = str(groupName) if cmds.objExists(newGroupName): existingGroups = cmds.ls("Group__*", transforms=True) highestSuffix = utils.findHighestTrailingNumber(existingGroups, groupName+"_") highestSuffix += 1 newGroupName = str(groupName) + "_" + str(highestSuffix) groupNames.append([group, newGroupName]) self.resolveNameChangeMirrorLinks(groupNames, tempNamespace) groupContainer = tempNamespace+"Group_container" if cmds.objExists(groupContainer): cmds.lockNode(groupContainer, lock=False, lockUnpublished=False) for name in groupName: cmds.rename(name[0], name[1]) if cmds.objExists(groupContainer): cmd.lockNode(groupContainer, lock=True, lockUnpublished=True) return groupNames
def duplicateControlModule(self, withAnimation=True): # Unlock containers characterContainer = self.characterNamespaceOnly + ":character_container" blueprintContainer = self.blueprintNamespace + ":module_container" moduleContainer = self.moduleContainer containers = [ characterContainer, blueprintContainer, moduleContainer] for c in containers: cmds.lockNode(c, lock=False, lockUnpublished=False) # Find all the animation nodes and determine which are user created, space switch, etc. cmds.namespace(setNamespace=self.blueprintNamespace + ":" + self.moduleNamespace) allAnimationNodes = cmds.namespaceInfo(listOnlyDependencyNodes=True) # Get all the animation curves allAnimationNodes = cmds.ls(allAnimationNodes, type="animCurve") # Find all contained animation nodes containedAnimationNodes = cmds.container(moduleContainer, q=True, nodeList=True) containedAnimationNodes = cmds.ls(containedAnimationNodes, type="animCurve") animationNodes = [] spaceSwitchAnimationNodes = [] for node in allAnimationNodes: if not node in containedAnimationNodes: animationNodes.append(node) else: if node.rpartition("_")[2] == "currentSpace": spaceSwitchAnimationNodes.append(node) # Set namespace back to Root cmds.namespace(setNamespace=":") utils.addNodeToContainer(moduleContainer, animationNodes) # Create temp namespace to duplicate nodes into. cmds.namespace(addNamespace="TEMP") cmds.namespace(setNamespace="TEMP") # Duplicate the entire module container cmds.duplicate(moduleContainer, inputConnections=True) cmds.namespace(setNamespace=":"+self.blueprintNamespace) moduleNamespaces = cmds.namespaceInfo(listOnlyNamespaces=True) baseModuleNamespace = self.moduleNamespace.rpartition("_")[0] + "_" baseNamespace = self.blueprintNamespace + ":" + baseModuleNamespace highestSuffix = utils.findHighestTrailingNumber(moduleNamespaces, baseNamespace) highestSuffix += 1 newModuleNamespace = baseModuleNamespace + str(highestSuffix) # Add the new module namespace and set the default namespace back to root. cmds.namespace(addNamespace=newModuleNamespace) cmds.namespace(setNamespace=":") cmds.namespace(moveNamespace=["TEMP", self.blueprintNamespace+":"+newModuleNamespace]) cmds.namespace(removeNamespace="TEMP") oldModuleNamespace = self.moduleNamespace self.moduleNamespace = newModuleNamespace newModuleContainer = self.blueprintNamespace + ":" + self.moduleNamespace + ":module_container" utils.addNodeToContainer(blueprintContainer, newModuleContainer) # Generate a publish name list. Name of the attribute on the container and the name of the attribute it is driving. publishedNameList = [] publishedNames = cmds.container(newModuleContainer, q=True, publishName=True) for name in publishedNames: drivenAttribute = cmds.connectionInfo(newModuleContainer+"."+name, getExactSource=True) publishedNameList.append( (name, drivenAttribute) ) # Now loop through the attribute names and rename the names on the container. #unbind the attributes on the new container. # This seems to be failing on the first .visibility attribute. A maya command error is returned. # I am adding a try so I can get past this for now. No fing clue why I error out. for name in publishedNameList: try: cmds.container(newModuleContainer, edit=True, unbindAndUnpublish=name[1]) nameInfo = name[0].partition(oldModuleNamespace) newName = nameInfo[0] + self.moduleNamespace + nameInfo[2] # Now that we have the new attribute name, publish that name to our container. cmds.container(newModuleContainer, edit=True, publishAndBind=[name[1], newName]) except: pass self.moduleContainer = moduleContainer oldPublishedNames = self.findAllNamesPublishedToOuterContainers() newPublishedNames = [] for name in oldPublishedNames: nameInfo = name.partition(oldModuleNamespace) newPublishedNames.append( (nameInfo[0] + self.moduleNamespace + nameInfo[2])) # Loop through and publish attributes to outer container. self.publishedNames = list(newPublishedNames) self.moduleContainer = newModuleContainer self.publishModuleContainerNamesToOuterContainers() deleteNodes = [] moduleJointsGrp = self.blueprintNamespace+":"+self.moduleNamespace+":joints_grp" self.joints = utils.findJointChain(moduleJointsGrp) for joint in self.joints: if cmds.objExists(joint+"_multiplyRotationsWeight"): deleteNodes.append(joint+"_multiplyRotationsWeight") if cmds.objExists(joint+"_multiplyTranslationWeight"): deleteNodes.append(joint+"_multiplyTranslationWeight")\ if cmds.objExists(joint+"_multiplyScaleWeight"): deleteNodes.append(joint+"_multiplyScaleWeight") cmds.delete(deleteNodes, inputConnectionsAndNodes=False) utilityNodes = self.setupBlueprintWeightBasedBlending() utils.addNodeToContainer(newModuleContainer, utilityNodes)
def duplicateControlModule(self,withAnimation=True): characterContainer = self.characterNamespaceOnly + ':character_container' blueprintContainer = self.blueprintNamespace + ':module_container' moduleContainer = self.moduleContainer containers = [characterContainer, blueprintContainer,moduleContainer] for c in containers: cmds.lockNode(c, lock=False, lockUnpublished=False) cmds.namespace(setNamespace=self.blueprintNamespace + ':' + self.moduleNamespace) allAnimationNodes = cmds.namespaceInfo(listOnlyDependencyNodes=True) allAnimationNodes = cmds.ls(allAnimationNodes, type='animCurve') containedAnimationNodes = cmds.container(moduleContainer, q=True, nodeList=True) containedAnimationNodes = cmds.ls(containedAnimationNodes, type='animCurve') animationNodes = [] spaceSwitchAnimationNodes = [] for node in allAnimationNodes: if not node in containedAnimationNodes: animationNodes.append(node) else: if node.rpartition('_')[2] == 'currentSpace': spaceSwitchAnimationNodes.append(node) cmds.namespace(setNamespace=':') utils.addNodeToContainer(moduleContainer, animationNodes) cmds.namespace(addNamespace='TEMP') cmds.namespace(setNamespace='TEMP') cmds.duplicate(moduleContainer, inputConnections=True) cmds.namespace(setNamespace=':'+self.blueprintNamespace) moduleNamespaces = cmds.namespaceInfo(listOnlyNamespaces=True) baseModuleNamespace = self.moduleNamespace.rpartition('_')[0] + '_' baseNamespace = self.blueprintNamespace + ':' + baseModuleNamespace highestSuffix = utils.findHighestTrailingNumber(moduleNamespaces, baseNamespace) highestSuffix += 1 newModuleNamespace = baseModuleNamespace + str(highestSuffix) cmds.namespace(addNamespace=newModuleNamespace) cmds.namespace(setNamespace=':') cmds.namespace(moveNamespace=['TEMP',self.blueprintNamespace+':'+newModuleNamespace]) cmds.namespace(removeNamespace='TEMP') oldModuleNamespace = self.moduleNamespace self.moduleNamespace = newModuleNamespace newModuleContainer = self.blueprintNamespace + ':' + self.moduleNamespace + ':module_container' utils.addNodeToContainer(blueprintContainer, newModuleContainer) publishedNameList = [] publishedNames = cmds.container(newModuleContainer, q=True, publishName=True) for name in publishedNames: drivenAttribute = cmds.connectionInfo(newModuleContainer + '.' + name, getExactSource=True) publishedNameList.append((name,drivenAttribute)) for name in publishedNameList: cmds.container(newModuleContainer,edit=True, unbindAndUnpublish=name[1]) nameInfo = name[0].partition(oldModuleNamespace) newName = nameInfo[0] + self.moduleNamespace + nameInfo[2] cmds.container(newModuleContainer,edit=True,publishAndBind=[name[1],newName]) self.moduleContainer = moduleContainer oldPublishedNames = self.findAllNamesPublishedToOuterContainers() newPublishedNames = [] for name in oldPublishedNames: nameInfo = name.partition(oldModuleNamespace) newPublishedNames.append((nameInfo[0] + self.moduleNamespace + nameInfo[2])) self.publishedNames = list(newPublishedNames) self.moduleContainer = newModuleContainer self.publishModuleContainerNamesToOuterContainers() deleteNodes = [] moduleJointsGrp = self.blueprintNamespace + ':' + self.moduleNamespace + ':joints_grp' self.joints = utils.findJointChain(moduleJointsGrp) for joint in self.joints: if cmds.objExists(joint + '_multiplyRotationsWeight'): deleteNodes.append(joint + '_multiplyRotationsWeight') if cmds.objExists(joint + '_multiplyTranslationWeight'): deleteNodes.append(joint + '_multiplyTranslationWeight') if cmds.objExists(joint + '_multiplyScaleWeight'): deleteNodes.append(joint + '_multiplyScaleWeight') cmds.delete(deleteNodes, inputConnectionsAndNodes=False) utilityNodes = self.setupBlueprintWeightBasedBlending() utils.addNodeToContainer(newModuleContainer, utilityNodes) cmds.container(moduleContainer,edit=True, removeNode=animationNodes) cmds.container(blueprintContainer,edit=True, removeNode=animationNodes) cmds.container(characterContainer,edit=True, removeNode=animationNodes) newAnimationNodes = [] for node in animationNodes: nodeName = utils.stripAllNamespaces(node)[1] newAnimationNodes.append(self.blueprintNamespace+':'+self.moduleNamespace+':'+nodeName) newSpaceSwitchAnimationNodes = [] for node in newSpaceSwitchAnimationNodes: nodeName = utils.stripAllNamespaces(node)[1] newSpaceSwitchAnimationNodes.append(self.blueprintNamespace+':'+self.moduleNamespace+':'+nodeName) if withAnimation: cmds.container(newModuleContainer,edit=True, removeNode=newAnimationNodes) cmds.container(blueprintContainer,edit=True, removeNode=newAnimationNodes) cmds.container(characterContainer,edit=True, removeNode=newAnimationNodes) else: if len(newAnimationNodes) >0: cmds.delete(newAnimationNodes) if len(newSpaceSwitchAnimationNodes) > 0: cmds.delete(newSpaceSwitchAnimationNodes) containers.append(newModuleContainer) for c in containers: cmds.lockNode(c,lock=True,lockUnpublished=True)
def duplicateControlModule(self, withAnimation=True): # Unlock containers characterContainer = self.characterNamespaceOnly + ":character_container" blueprintContainer = self.blueprintNamespace + ":module_container" moduleContainer = self.moduleContainer containers = [characterContainer, blueprintContainer, moduleContainer] for c in containers: cmds.lockNode(c, lock=False, lockUnpublished=False) # Find all the animation nodes and determine which are user created, space switch, etc. cmds.namespace(setNamespace=self.blueprintNamespace + ":" + self.moduleNamespace) allAnimationNodes = cmds.namespaceInfo(listOnlyDependencyNodes=True) # Get all the animation curves allAnimationNodes = cmds.ls(allAnimationNodes, type="animCurve") # Find all contained animation nodes containedAnimationNodes = cmds.container(moduleContainer, q=True, nodeList=True) containedAnimationNodes = cmds.ls(containedAnimationNodes, type="animCurve") animationNodes = [] spaceSwitchAnimationNodes = [] for node in allAnimationNodes: if not node in containedAnimationNodes: animationNodes.append(node) else: if node.rpartition("_")[2] == "currentSpace": spaceSwitchAnimationNodes.append(node) # Set namespace back to Root cmds.namespace(setNamespace=":") utils.addNodeToContainer(moduleContainer, animationNodes) # Create temp namespace to duplicate nodes into. cmds.namespace(addNamespace="TEMP") cmds.namespace(setNamespace="TEMP") # Duplicate the entire module container cmds.duplicate(moduleContainer, inputConnections=True) cmds.namespace(setNamespace=":" + self.blueprintNamespace) moduleNamespaces = cmds.namespaceInfo(listOnlyNamespaces=True) baseModuleNamespace = self.moduleNamespace.rpartition("_")[0] + "_" baseNamespace = self.blueprintNamespace + ":" + baseModuleNamespace highestSuffix = utils.findHighestTrailingNumber( moduleNamespaces, baseNamespace) highestSuffix += 1 newModuleNamespace = baseModuleNamespace + str(highestSuffix) # Add the new module namespace and set the default namespace back to root. cmds.namespace(addNamespace=newModuleNamespace) cmds.namespace(setNamespace=":") cmds.namespace(moveNamespace=[ "TEMP", self.blueprintNamespace + ":" + newModuleNamespace ]) cmds.namespace(removeNamespace="TEMP") oldModuleNamespace = self.moduleNamespace self.moduleNamespace = newModuleNamespace newModuleContainer = self.blueprintNamespace + ":" + self.moduleNamespace + ":module_container" utils.addNodeToContainer(blueprintContainer, newModuleContainer) # Generate a publish name list. Name of the attribute on the container and the name of the attribute it is driving. publishedNameList = [] publishedNames = cmds.container(newModuleContainer, q=True, publishName=True) for name in publishedNames: drivenAttribute = cmds.connectionInfo(newModuleContainer + "." + name, getExactSource=True) publishedNameList.append((name, drivenAttribute)) # Now loop through the attribute names and rename the names on the container. #unbind the attributes on the new container. # This seems to be failing on the first .visibility attribute. A maya command error is returned. # I am adding a try so I can get past this for now. No fing clue why I error out. for name in publishedNameList: try: cmds.container(newModuleContainer, edit=True, unbindAndUnpublish=name[1]) nameInfo = name[0].partition(oldModuleNamespace) newName = nameInfo[0] + self.moduleNamespace + nameInfo[2] # Now that we have the new attribute name, publish that name to our container. cmds.container(newModuleContainer, edit=True, publishAndBind=[name[1], newName]) except: pass self.moduleContainer = moduleContainer oldPublishedNames = self.findAllNamesPublishedToOuterContainers() newPublishedNames = [] for name in oldPublishedNames: nameInfo = name.partition(oldModuleNamespace) newPublishedNames.append( (nameInfo[0] + self.moduleNamespace + nameInfo[2])) # Loop through and publish attributes to outer container. self.publishedNames = list(newPublishedNames) self.moduleContainer = newModuleContainer self.publishModuleContainerNamesToOuterContainers() deleteNodes = [] moduleJointsGrp = self.blueprintNamespace + ":" + self.moduleNamespace + ":joints_grp" self.joints = utils.findJointChain(moduleJointsGrp) for joint in self.joints: if cmds.objExists(joint + "_multiplyRotationsWeight"): deleteNodes.append(joint + "_multiplyRotationsWeight") if cmds.objExists(joint + "_multiplyTranslationWeight"): deleteNodes.append(joint+"_multiplyTranslationWeight")\ if cmds.objExists(joint + "_multiplyScaleWeight"): deleteNodes.append(joint + "_multiplyScaleWeight") cmds.delete(deleteNodes, inputConnectionsAndNodes=False) utilityNodes = self.setupBlueprintWeightBasedBlending() utils.addNodeToContainer(newModuleContainer, utilityNodes)