Esempio n. 1
0
 def connectOutputToInput(self):
     """
         Gets input and outputs from GUI and will connect them
     """
     type = "trans"
     connectInputIconTextScroll = "connectInputIconTextScroll"
     connectOutputIconTextScroll = "connectOutputIconTextScroll"
     connectionKey = ""
     # get Input
     inputKey = Util.getFirst(self.queryInput(connectInputIconTextScroll))
     # get Output
     outputKey = Util.getFirst(self.queryInput(connectOutputIconTextScroll))
     
     connectionKey = (outputKey + "_" + inputKey)
     
     # get Modules
     inputModule = self.queryElement("connectInputButton")
     outputModule = self.queryElement("connectOutputButton")
     
     # get input / output objects
     inputObj = self.rigInstance.getInput(inputModule, inputKey)
     outputObj = self.rigInstance.getOutput(outputModule, outputKey)
     
     inputPlug = (inputModule + "." + inputKey)
     outputPlug = (outputModule + "." + outputKey)
     
     # perform connection based on type
     self.rigInstance.Modules[inputModule].storeConnection(connectionKey, inputPlug, outputPlug , type)
     self.rigInstance.createConnection( inputModule , connectionKey )
Esempio n. 2
0
        def blueprint(self,**kwargs):
			"""
				Creates a joint chain can be used for spine
			"""
			
			# create registries
			self.createRegistry("regBlueprintTransform")
			self.createRegistry("regBlueprintShape")
			
			# get blueprint attributes
			jointNo= int(self.blueprintAttributes["Joint number"].value)
			
			#create module top group
			rootGrp = cmds.group( n = (self.name + "Blueprint_GRP"), em = True )
			jointGrp = cmds.group( n = (self.name + "BlueprintJoint_GRP"), em = True, p = rootGrp )
			
			# create blueprinters
			spineChainData = Util.createBlueprinterChain( (self.name + "SpineChainBlueprinter"), {"chainNo": jointNo})
			spineChainJoints = spineChainData["jnt"]
			spineChainSctls = spineChainData["sctl"]
			
			cmds.parent(spineChainJoints[0], jointGrp)
			cmds.parent(spineChainData["root"], rootGrp)
			
			cmds.parent(rootGrp, self.rootGrp)
			
			# store joints and controls
			self.storeBlueprinterJoints( spineChainJoints )
			self.storeBlueprinterControls( spineChainSctls )
			
			# register Blueprinters
			self.registerObjects(Util.createSingleArray(spineChainSctls), "regBlueprintTransform")
Esempio n. 3
0
 def __init__(self, name):
     # create update variable if module is reloaded get variables from
     # container
     self.name = name
     self.update = 0
     self.blueprintVar = 0
     self.rigVar = 0
     self.connectVar = 0
     self.registeredAttributes= []
     self.inputs = {}
     self.outputs = {}
     self.connections = {}
     
     # create default hierarchy for module
     # if Module already exists use existing objects
     if Util.checkForExistingObject( (self.name + "_CNT"), "container" ):
         self.container = (self.name + "_CNT")
     else:
         self.container = cmds.container( n= (self.name + "_CNT"))
         Util.storeString(self.container, "type", "Module")
     if Util.checkForExistingObject( (self.name + "Root_GRP"), "transform" ):
         self.rootGrp = (self.name + "Root_GRP")
     else:
         self.rootGrp = cmds.group( n = (self.name + "Root_GRP"), em = True )
         self.storeInput(self.rootGrp,"root")
     
     # class specific init
     self.initialize()
Esempio n. 4
0
		def reloadModule(self,module):
			"""
				Gets data from container and rerigs python object
			"""
			moduleType = Util.getString(module, "type")
			command = ("module = " + str(moduleType) + "." + str(moduleType) + "('"+ Util.removeSuffix(module) +"')")
			exec command
			return module
Esempio n. 5
0
 def registerObjects(self, objects, type):
     """
         will connect object to container attribute so specific commands can be called on it
         later
     """
     if cmds.objExists( (self.container + "." + type) ):
         for object in objects:
             Util.addAttr(object, type, "message" )
             cmds.connectAttr((self.container + "." + type), (object + "." + type) )
     else:
         cmds.error( (self.container + "." + type) + " not found" )
Esempio n. 6
0
 def registerAttribute(self, attrName):
     """
         Creates array of attribute names that will store data on module
     """
     if cmds.objExists((self.container + ".regAttribute")) == False:
         Util.addStringArrayAttribute(self.container,"regAttribute",[attrName])
     else:
         data = cmds.getAttr((self.container + ".regAttribute"))
         data.append(attrName)
         Util.setStringArrayData(self.container,"regAttribute",data)
         self.registeredAttributes.append(attrName)
Esempio n. 7
0
        def rig(self,**kwargs):
			# Variables
			clusterCtls = []
			
			# create registries
			self.createRegistry("regRigTransform")
			self.createRegistry("regRigShape")
			
			# Check for module container
			rootGrp = cmds.group( n = (self.name + "Rig_GRP"), em = True )
			jointGrp = cmds.group( n = (self.name + "Joint_GRP"), em = True, p= rootGrp)
			setupGrp = cmds.group( n = (self.name + "Setup_GRP"), em = True, p= rootGrp)
			controlGrp = cmds.group( n = (self.name + "Control_GRP"), em = True, p= rootGrp)
			
			# Get blueprinter joints
			blueprinters  = self.getBlueprinterJoints()
			for joint in blueprinters:
				if cmds.objExists(joint) == False:
					cmds.error(joint + " not found!")
			
			# Duplicate joints
			joints = Util.duplicateChain( self.name , blueprinters)
			cmds.parent(joints[0],jointGrp)
			
			# Hide blueprinters joints
			cmds.setAttr((self.name + "Blueprint_GRP" + ".v"), 0)
			
			#cmds.ikHandle()
			handleData = Util.createSplineIk(self.name, joints, sol= "ikSplineSolver")
			clusterList = Util.clusterizeCurve( handleData["CRV"] )
			
			cmds.parent(handleData["IK"], setupGrp)
			
			#create controls
			for cluster in clusterList:
				clusterName = Util.removeSuffix( cluster[0] )
				clusterCtl = Util.createControl( clusterName, {"match":cluster[0]}  )
				
				cmds.parent(cluster[1], clusterCtl[0] )
				cmds.parent(clusterCtl[1], controlGrp )
				clusterCtls.append(clusterCtl)
				
			# parent controls
			for x in range(1,  len(clusterCtls) ):
				cmds.parent( clusterCtls[x][1], clusterCtls[x-1][0] )
			cmds.parent(rootGrp, self.rootGrp)
			
			# store outputs
			self.storeOutput(clusterCtls[3][0],"endControl")
Esempio n. 8
0
		def loadBlueprintData(self, modules = None):
			"""
				Loads blueprint data onto blueprinter
			"""
			if modules == None:
				modules = self.getModules()
			
			# open file from path in UI
			self.UI.getFilePath()
			for module in modules:
				# Load transforms
				filePath = (str(self.UI.filePath) + module + "BlueprintData.txt")
				Util.loadTransforms(filePath)
				# Load Attributeibutes
			print ("Blueprint data loaded")
Esempio n. 9
0
 def updateRigAttributes(self,args):
     """
         Gets selected module and lists attributes
     """
     functArgs = Util.defaultArgs({}, args )
     # Check rigIconScroll element exists
     if self.inputs.has_key("rigList"):
         selectedModule = self.queryInput("rigList")
         if selectedModule:
             # Get selected element
             selectedModule = Util.getFirst(selectedModule)
             # Load selected objects attributes
             self.loadAttributes('rig',selectedModule.strip())
     else:
         pass
Esempio n. 10
0
		def duplicateModule(self, moduleName, newModuleName):
			"""
				duplicated module for now only handles blueprint
			"""
			# duplicate blueprint module
			Util.duplicateBlueprint(moduleName, newModuleName)
			# copy instance
			self.Modules[newModuleName] = copy.deepcopy(self.Modules[moduleName])
			# rename instance data
			self.Modules[newModuleName].name = newModuleName
			self.Modules[newModuleName].rootGrp = (newModuleName + "Root_GRP")
			self.Modules[newModuleName].container = (newModuleName + "_CNT")
			
			joints = self.Modules[newModuleName].getBlueprinterJoints()
			for x in range(len(joints)):
				joints[x] = joints[x].replace(moduleName,newModuleName)
			self.Modules[newModuleName].storeBlueprinterJoints(joints)
Esempio n. 11
0
 def getRegisteredObjects(self,type):
     """
         Will return objects connected to registry attribute
     """
     if cmds.objExists( (self.container + "." + type) ):
         return Util.getConnectedObjects( (self.container + "." + type) )
     else:
         cmds.error( (self.container + "." + type) + " not found" )
Esempio n. 12
0
 def initialise(self,args, **kwds):
     """
         RigUI initalise function
     """
     self.rigInstance = None
     self.rigInstance = Util.checkForKwarg("Rig",args)
     self.filePath = ""
     self.blueprintAttributeUIElements = {}
     self.rigAttributeUIElements = {}
Esempio n. 13
0
		def renameModule(self, module, name):
			"""
				Renames module
			"""
			# Rename container and all module components
			moduleContainer = self.Modules[module].container
			moduleList = cmds.container( (moduleContainer), query= True, nodeList= True )
			# Rename module instance and dictionary keys
			for obj in moduleList:
				if cmds.objExists(obj):
					newName = obj.replace(module, name )
					cmds.rename(obj, newName)
			newName = moduleContainer.replace(module, name )
			cmds.rename(moduleContainer, newName) 
			# Change dict entry in Rig instance
			self.Modules[Util.removeSuffix(newName)] = copy.deepcopy(self.Modules[module])
			self.Modules[Util.removeSuffix(newName)].container = newName
			del self.Modules[module]
Esempio n. 14
0
 def storeConnection(self, connectionKey, inputPlug, outputPlug , type, attrName= "None"):
     """
         Store connection data between output to input on current module
     """
     
     connectAttr = ("connection_" + connectionKey)
     connectDataAttr = ("connection_" + connectionKey + "_data")
     connectInputAttr = ("connection_" + connectionKey + "_input")
     connectOutputAttr = ("connection_" + connectionKey + "_output")
     
     if cmds.objExists( (self.container + "." + connectAttr) ) == False:
         Util.addAttr(self.container, connectAttr, "message")
         # Store connection Data
         connectionData = ["type:",type, "attr:",attrName ,"input:",inputPlug ,"output:",outputPlug, "connectionKey:",connectionKey ] 
         Util.addStringArrayAttribute(self.container , connectDataAttr, connectionData )
         self.connections[connectionKey] = {"input":inputPlug,"output":outputPlug, "connectAttr":connectAttr}
         self.registerAttribute( connectDataAttr )
     else:
         cmds.warning( "Connection value :" + (self.container + "." + connectAttr) + " already exists" )
Esempio n. 15
0
		def __init__(self, name, **kwargs):
				classArgs = {"UIFile":"default.py","rerigUI":True}
				#classArgs =  dict(classArgs.items() + kwargs.items())
				classArgs =	 Util.defaultArgs( classArgs,  kwargs)
				self.Modules = {}
				self.connections = {}
				self.name = name
				self.UIFile =  classArgs["UIFile"]
				if classArgs["rerigUI"]:
					self.UI = self.initialiseUI()
Esempio n. 16
0
		def saveBlueprintData(self, modules = None ):
			"""
				Saves blueprint data into file
			"""
			if modules == None:
				modules = self.getModules()
			
			# refresh UI path
			self.UI.getFilePath()  
			bluePrintFilePath = (str(self.UI.filePath) + "BlueprintData.txt")
			# Save module data
			Util.saveBlueprintModuleData( bluePrintFilePath, modules )
			# Save detailed info in seperate files
			for module in modules:
				# Save blueprint transforms
				filePath = (str(self.UI.filePath) + module + "BlueprintData.txt")
				Util.saveTransforms(filePath, module, Util.getRegisteredObjects(module,"regBlueprintTransform") )
				# Save Attributeibute data
			print ("Blueprint data saved")
Esempio n. 17
0
 def rigModules(self,args):
     """
         Get selected modules and rig them recersively
     """
     moduleList= []
     
     if self.elementExists("rigList") == False:
         cmds.warning("No modules found in scene")
         return None
     
     selectedModule = Util.getFirst(self.queryInput("rigList"))
     selectedModule = selectedModule.strip()
     moduleList = self.recursiveGetModules(selectedModule)
     
     for module in moduleList:
         moduleName = Util.removeSuffix(module)
         moduleName = moduleName.strip()
         self.rigInstance.rigModule({"name": moduleName})
     # Load rig data
     self.rigInstance.loadRigData()
Esempio n. 18
0
		def rigModule(self,args):
			"""
				Run rig method for module
			"""
			# get module name
			defaultArgs = {"name":"default"}
			functArgs =	 Util.defaultArgs( defaultArgs,	 args)
			name = functArgs["name"]
			
			# Check that root is built
			if self.rootExists() == False:
				cmds.error("Root container not found during rig")
			self.refreshModuleList()
			
			# check module exists and rig has not been run
			if Util.moduleExists(name) and self.checkMethod(name, "rig"):
				mod = self.Modules[name]
				mod.rig()
			else:
				print ("Module \"" + name + "\" already built!")
Esempio n. 19
0
		def getModules(self):
			moduleKeys = self.Modules.keys()
			# remove root as it will be a duplicate key
			moduleKeys = [ x for x in moduleKeys if not x == "root"]
			
			modules = []
			for key in moduleKeys:
				name  = self.Modules[key].name
				if Util.moduleExists(name):
					modules.append(name)
			return modules
Esempio n. 20
0
    def loadModules(self,args,**kwargs):
        """ 
            Load text in list for each module available
        """
        defaultArgs = {"key": "rigList",
                        "parent": "rigScroll"}
        functArgs =  Util.defaultArgs( defaultArgs, args)
        selectCommand = ("NWRig" + ".UI.updateRigAttributes({})")
        rootContainer = ""
        iconTextScroll = ""
        moduleList = []
        
        # Overwrite select command
        kwargs["sc"] = selectCommand
        
        if self.rigInstance.rootExists():
            self.rigInstance.refreshModuleList()
            rootContainer = self.rigInstance.Modules["root"].name
        else:
            if self.elementExists(functArgs["key"]):
                return self.windowElements[functArgs["key"].fullPath]
            else:
                cmds.warning("No modules found in scene")
                return None

        # File list of modules in scene indent children
        moduleList = self.recursiveGetModules( (rootContainer + "_CNT") )
        
        # Add module list to funct args
        functArgs =  Util.defaultArgs( functArgs, {"append": moduleList} )
        
        if self.elementExists(functArgs["key"]):
            combinedArgs = Util.defaultArgs( functArgs, kwargs)
            combinedArgs.pop("key")
            iconTextScroll = self.editElement(functArgs["key"], ra= True)
            iconTextScroll = self.editElement(functArgs["key"], **combinedArgs)
        else:
            iconTextScroll = self.iconTextScrollList(functArgs, **kwargs)
        
        self.inputs[functArgs["key"]] = self.windowElements[functArgs["key"]]
        return iconTextScroll
Esempio n. 21
0
 def deleteModule(self):
     """
         Deletes module
     """
     if self.elementExists("rigList") == False:
         cmds.warning("No modules found in scene")
         return None
     
     selectedModule = Util.getFirst(self.queryInput("rigList"))
     selectedModule = String.removeSuffix(selectedModule.strip())
     self.rigInstance.deleteModule(selectedModule)
     self.loadModules({})
Esempio n. 22
0
 def updateBlueprintAttributes(self,args):
     """
         Gets selected module and lists attributes
     """
     functArgs = Util.defaultArgs({}, args )
     # Check blueprintIconScroll element exists
     if self.windowElements.has_key("blueprintAttributeframe"):
         # Load selected objects attributes
         self.loadAttributes('blueprint',args["module"])
         self.editElement("blueprintTextField",tx = args["module"])
     else:
         pass
Esempio n. 23
0
 def renameModule(self):
     """
         Will rename current module
     """
     if self.elementExists("rigList") == False:
         cmds.warning("No modules found in scene")
         return None
     
     selectedModule = Util.getFirst(self.queryInput("rigList"))
     selectedModule = String.removeSuffix(selectedModule.strip())
     self.createValueWindow("Enter new module name", "default","NWRig.renameModule(\""+selectedModule+"\", %)")
     self.loadModules({})
Esempio n. 24
0
 def updateInputOutputs(self):
     """
         finds attributes on module with "input_" & "output_" prefix then populates dicts
     """
     
     # Get input attrs
     inputsAttrs = cmds.listAttr( self.container, st='input_*')
     # Get output attrs
     outputsAttrs = cmds.listAttr( self.container, st='output_*')
     
     if inputsAttrs:
         for attr in inputsAttrs:
             # get attr key
             key = Util.getSuffix(attr)
             if key != "data":
                 # get connected obj
                 objs = Util.getConnectedObjects( (self.container + "." + attr) )
                 # store obj
                 self.inputs[key] = Util.getFirst(objs)
                     
     if outputsAttrs:
         for attr in outputsAttrs:
             # get attr key
             key = Util.getSuffix(attr)
             if key != "data":
                 # get connected obj
                 objs = Util.getConnectedObjects( (self.container + "." + attr) )
                 # store obj
                 self.outputs[key] = Util.getFirst(objs)
Esempio n. 25
0
 def populateConnectPopupMenu(self, popupKey, connetionType = "Input"):
     """
         Finds modules in scene and lists them in popup menu
     """
     kwargs = {}
     # get module list
     moduleList = self.rigInstance.getModuleContainers()
     for module in moduleList:
         moduleName = Util.removeSuffix(module)
         key = (moduleName + connetionType + "MenuItem")
         kwargs["command"] = ("NWRig.UI.setConnectionModule(\"" + moduleName + "\",\"" + connetionType + "\")")
         # clear popup menu
         if self.elementExists(key):
             self.removeElement(key)
         moduleMenuItem = self.menuItem({'key':key,'label':module,'parent':popupKey}, **kwargs)  
Esempio n. 26
0
		def blueprintModule(self, name ,module):
			"""
				Run blueprint method for module
			"""	 
			if Util.moduleExists(name):
				if self.checkMethod( name,"blueprint"):
					self.Modules[name].blueprint()
					
					if module != "Root":
						cmds.parent(self.Modules[name].rootGrp, self.Modules["root"].groups["modules"])
						cmds.container( self.Modules["root"].container, edit=True, an= self.Modules[name].container)
				else:
					cmds.error("Blueprint already built for " + name)
			else:
				cmds.error("Module "+name+" not found in rig instance")
Esempio n. 27
0
 def mirrorBlueprint(self):
     """
         duplciates blueprint
     """
     if self.elementExists("rigList") == False:
         cmds.warning("No modules found in scene")
         return None
         
     selectedModule =self.queryInput("rigList")
     if not selectedModule:
         cmds.error("Select module to duplicate in rig menu.")
     selectedModule = Util.getFirst(selectedModule)
     selectedModule = String.removeSuffix(selectedModule.strip())
     self.createValueWindow("Enter new module name", "default","NWRig.mirrorModule(\""+selectedModule+"\", %, 'x')")
     self.loadModules({})
Esempio n. 28
0
		def refreshModuleList(self):
			"""
				Clears and refreshes module instances
			"""
			rootCnt = (self.name + "_CNT")
			rootModule = {}
			# check if module list is empty
			if len(self.Modules) == 0:
				# Find root and find it's children
				if self.rootExists():
					# populate module list
					rootModule["root"] = self.reloadModule(rootCnt)
					childModules = self.getContainerChildren(rootCnt)
					self.Modules = Util.defaultArgs( rootModule,  childModules)
				else:
					smds.error("Root containter not found for refresh")
Esempio n. 29
0
		def getContainerChildren(self,cont):
			"""
				Finds all children containers of passed container
			"""
			containers = {}
			if cmds.objExists(cont):
				# populate module list
				contents = cmds.container(cont, query= True, nodeList= True)
				if contents == None:
					return containers
				for item in contents:
					if cmds.objectType(item) == "container":
						containers[Util.removeSuffix(item)] = self.reloadModule(item)
						# combine and overwrite lists
						containers = dict(containers.items() + (self.getContainerChildren(item)).items())
				return containers
			else:
				cmds.error("Root containter not found for refresh")
Esempio n. 30
0
		def createConnection(self, inputModule, connectionKey):
			"""
				Connect objects based on connection data
			"""
			inputModule = self.Modules[inputModule]
			# Check connection exists
			if not inputModule.connections.has_key(connectionKey):
				cmds.error("Connection data not found")
			inputPlug = inputModule.connections[connectionKey]["input"]
			outputPlug = inputModule.connections[connectionKey]["output"]
			connectionAttr = inputModule.connections[connectionKey]["connectAttr"]
			connectionDataAttr = (connectionAttr + "_data")
			
			inputModule = inputPlug.split(".")[0]
			outputModule = outputPlug.split(".")[0]
			
			inputKey = Util.getSuffix( inputPlug.split(".")[1] )
			outputey = Util.getSuffix( outputPlug.split(".")[1] )
			
			input = self.getInput(inputModule, inputKey)
			output = self.getOutput(outputModule, outputey)
			
			# Get connection data
			connectionData = cmds.getAttr( (inputModule + "_CNT." + connectionDataAttr) )
			AttributeName = connectionData[3]
			type = AttributeName = connectionData[1]
			
			if type == "trans":
				cmds.parentConstraint(output,input, mo= False)
			elif type == "transMo":
				cmds.parentConstraint(output,input, mo= True)
			elif type == "pos":
				cmds.pointConstraint(output,input, mo= False)
			elif type == "posMo":
				cmds.pointConstraint(output,input, mo= True)
			elif type == "rot":
				cmds.orientConstraint(output,input, mo= False)
			elif type == "rotMo":
				cmds.orientConstraint(output,input, mo= True)
			elif type == "scale":
				cmds.scaleConstraint(output,input)
			elif type == "matrix":
				Util.matrixConstraint(output, input, 0, {})
			elif type == "matrixMo":
				Util.matrixConstraint(output, input, 1, {})
			elif type == "Attribute":
				cmds.connectAttr(output, input, f= True)
			else:
				cmds.error( ("Connection type not found on connectionAttr: " + connectionAttr) )