def keyObj(model, object_names): """ Set the keyframe in the controls pass by a list in obj_names variable :param model: Name of the namespace that will define de the model :param object_names: names of the controls, without the name space :return: None """ nodes = [] for name in object_names: if len(model.split(":")) == 2: node = dag.findChild(model, model.split(":")[0] + ":" + name) else: node = dag.findChild(model, name) if not node and len(model.split(":")) == 2: mgear.log("Can't find object : %s:%s"%( model.split(":")[0], name), mgear.sev_error) elif not node: mgear.log("Can't find object : %s"%( name), mgear.sev_error) nodes.append(node) if not nodes: return pm.setKeyframe(*nodes)
def toggleAttr(model, object_name, attr_name): if len(model.split(":")) == 2: node = dag.findChild(model, model.split(":")[0] + ":" + object_name) else: node = dag.findChild(model, object_name) oAttr = node.attr(attr_name) if oAttr.type() in ["float", "bool"]: oVal = oAttr.get() if oVal == 1: oAttr.set(0) else: oAttr.set(1)
def toggleAttr(model, object_name, attr_name): nameSpace = getNamespace(model) if nameSpace: node = dag.findChild(nameSpace + ":" + object_name) else: node = dag.findChild(model, object_name) oAttr = node.attr(attr_name) if oAttr.type() in ["float", "bool"]: oVal = oAttr.get() if oVal == 1: oAttr.set(0) else: oAttr.set(1)
def quickSel(model, channel, mouse_button): qs_attr = model.attr("quicksel%s" % channel) if mouse_button == QtCore.Qt.LeftButton: # Call Selection names = qs_attr.get().split(",") if not names: return pm.select(clear=True) for name in names: ctl = dag.findChild(model, name) if ctl: ctl.select(add=True) elif mouse_button == QtCore.Qt.MidButton: # Save Selection names = [ sel.name().split("|")[-1] for sel in pm.ls(selection=True) if sel.name().endswith("_ctl") ] qs_attr.set(",".join(names)) elif mouse_button == QtCore.Qt.RightButton: # Key Selection names = qs_attr.get().split(",") if not names: return else: keyObj(model, names)
def quickSel(model, channel, mouse_button): """Select the object stored on the quick selection attributes Args: model (PyNode): The rig top node channel (str): The quick selection channel name mouse_button (QtSignal): Clicked mouse button Returns: None """ qs_attr = model.attr("quicksel%s" % channel) if mouse_button == QtCore.Qt.LeftButton: # Call Selection names = qs_attr.get().split(",") if not names: return pm.select(clear=True) for name in names: ctl = dag.findChild(model, name) if ctl: ctl.select(add=True) elif mouse_button == QtCore.Qt.MidButton: # Save Selection names = [sel.name().split("|")[-1] for sel in pm.ls(selection=True) if sel.name().endswith("_ctl")] qs_attr.set(",".join(names)) elif mouse_button == QtCore.Qt.RightButton: # Key Selection names = qs_attr.get().split(",") if not names: return else: keyObj(model, names)
def setFromHierarchy(self, root, branch=True): # Start mgear.log("Checking guide") # Get the model and the root self.model = root.getParent(generations=-1) while True: if root.hasAttr("comp_type") or self.model == root: break root = root.getParent() # --------------------------------------------------- # First check and set the options mgear.log("Get options") if not root.hasAttr("rig_name"): mgear.log("%s is not a proper rig guide."%self.model, mgear.sev_error) self.valid = False return self.setParamDefValuesFromProperty(self.model) # --------------------------------------------------- # Get the controlers mgear.log("Get controlers") self.controlers_org = dag.findChild(self.model, "controlers_org") if self.controlers_org: for child in self.controlers_org.getChildren(): self.controlers[child.name().split("|")[-1]] = child # --------------------------------------------------- # Components mgear.log("Get components") self.findComponentRecursive(root, branch) # Parenting if self.valid: mgear.log("Get parenting") for name in self.componentsIndex: compChild = self.components[name] compChild_parent = compChild.root.getParent() for name in self.componentsIndex: compParent = self.components[name] for localName, element in compParent.getObjects(self.model).items(): if element is not None and element == compChild_parent: compChild.parentComponent = compParent compChild.parentLocalName = localName break # More option values self.addOptionsValues() # End if not self.valid: mgear.log("The guide doesn't seem to be up to date. Check logged messages and update the guide.", mgear.sev_warning) mgear.log("Guide loaded from hierarchy in [ " + "Not Yet Implemented" + " ]")
def keyObj(model, object_names): nodes = [] for name in object_names: node = dag.findChild(model, name) if not node: mgear.log("Can't find object : %s.%s"%(model.name(), name), mgear.sev_error) nodes.append(node) if not nodes: return setKeyframe(*nodes)
def toggleAttr(model, object_name, attr_name): """Toggle a boolean attribute Args: model (PyNode): Rig top node object_name (str): The name of the control containing the attribute to toggle attr_name (str): The attribute to toggle """ nameSpace = getNamespace(model) if nameSpace: node = dag.findChild(nameSpace + ":" + object_name) else: node = dag.findChild(model, object_name) oAttr = node.attr(attr_name) if oAttr.type() in ["float", "bool"]: oVal = oAttr.get() if oVal == 1: oAttr.set(0) else: oAttr.set(1)
def setIndex(self, model): """Update the component index to get the next valid one. Args: model (dagNode): The parent model of the guide. """ self.model = model.getParent(generations=-1) # Find next index available while True: obj = dag.findChild(self.model, self.getName("root")) if not obj or (self.root and obj == self.root): break self.setParamDefValue("comp_index", self.values["comp_index"] + 1)
def quickSel(model, channel, mouse_button): qs_attr = model.attr("quicksel%s"%channel) if mouse_button == Qt.LeftButton: # Call Selection names = qs_attr.get().split(",") if not names: return select(clear=True) for name in names: ctl = dag.findChild(model, name) if ctl: ctl.select(add=True) elif mouse_button == Qt.MidButton: # Save Selection names = [ sel.name().split("|")[-1] for sel in ls(selection=True) if sel.name().endswith("_ctl") ] qs_attr.set(",".join(names)) elif mouse_button == Qt.RightButton: # Key Selection names = qs_attr.get().split(",") if not names: return
def selectObj(model, object_names, mouse_button, key_modifier): if mouse_button == Qt.RightButton: return nodes = [] for name in object_names: node = dag.findChild(model, name) if not node: mgear.log("Can't find object : %s.%s"%(model.name(), name), mgear.sev_error) nodes.append(node) if not nodes: return # Key pressed if key_modifier is None: select(nodes) elif key_modifier == Qt.NoModifier:# No Key select(nodes) elif key_modifier == Qt.ControlModifier: # ctrl select(nodes, add=True) elif key_modifier == Qt.ShiftModifier: # shift select(nodes, toggle=True) elif int(key_modifier) == Qt.ControlModifier + Qt.ShiftModifier: # ctrl + shift select(nodes, deselect=True) elif key_modifier == Qt.AltModifier: # alt select(nodes) elif int(key_modifier) == Qt.ControlModifier + Qt.AltModifier: # ctrl + alt select(nodes, add=True) elif int(key_modifier) == Qt.ShiftModifier + Qt.AltModifier: # shift + alt select(nodes, toggle=True) elif int(key_modifier) == Qt.ControlModifier + Qt.AltModifier + Qt.ShiftModifier: # Ctrl + alt + shift select(nodes, deselect=True) else: select(nodes)
def setFromHierarchy(self, root): """ Set the component guide from given hierarchy. Args: root (dagNode): The root of the hierarchy to parse. """ self.root = root self.model = self.root.getParent(generations=-1) # --------------------------------------------------- # First check and set the settings if not self.root.hasAttr("comp_type"): mgear.log("%s is not a proper guide." % self.root.longName(), mgear.sev_error) self.valid = False return self.setParamDefValuesFromProperty(self.root) # --------------------------------------------------- # Then get the objects for name in self.save_transform: if "#" in name: i = 0 while not self.minmax[name].max > 0 or i < self.minmax[ name].max: localName = string.replaceSharpWithPadding(name, i) node = dag.findChild(self.model, self.getName(localName)) if not node: break self.tra[localName] = node.getMatrix(worldSpace=True) self.atra.append(node.getMatrix(worldSpace=True)) self.pos[localName] = node.getTranslation(space="world") self.apos.append(node.getTranslation(space="world")) i += 1 if i < self.minmax[name].min: mgear.log( "Minimum of object requiered for " + name + " hasn't been reached!!", mgear.sev_warning) self.valid = False continue else: node = dag.findChild(self.model, self.getName(name)) if not node: mgear.log("Object missing : %s" % name, mgear.sev_warning) self.valid = False continue self.tra[name] = node.getMatrix(worldSpace=True) self.atra.append(node.getMatrix(worldSpace=True)) self.pos[name] = node.getTranslation(space="world") self.apos.append(node.getTranslation(space="world")) for name in self.save_blade: node = dag.findChild(self.model, self.getName(name)) if not node: mgear.log("Object missing : %s" % name, mgear.sev_warning) self.valid = False continue self.blades[name] = vec.Blade(node.getMatrix(worldSpace=True)) self.size = self.getSize()
def setFromHierarchy(self, root, branch=True): # Start mgear.log("Checking guide") # Get the model and the root self.model = root.getParent(generations=-1) while True: if root.hasAttr("comp_type") or self.model == root: break root = root.getParent() # --------------------------------------------------- # First check and set the options mgear.log("Get options") if not root.hasAttr("rig_name"): mgear.log("%s is not a proper rig guide." % self.model, mgear.sev_error) self.valid = False return self.setParamDefValuesFromProperty(self.model) # --------------------------------------------------- # Get the controlers mgear.log("Get controlers") self.controlers_org = dag.findChild(self.model, "controlers_org") if self.controlers_org: for child in self.controlers_org.getChildren(): self.controlers[child.name().split("|")[-1]] = child # --------------------------------------------------- # Components mgear.log("Get components") self.findComponentRecursive(root, branch) # Parenting if self.valid: mgear.log("Get parenting") for name in self.componentsIndex: compChild = self.components[name] compChild_parent = compChild.root.getParent() for name in self.componentsIndex: compParent = self.components[name] for localName, element in compParent.getObjects( self.model).items(): if element is not None and element == compChild_parent: compChild.parentComponent = compParent compChild.parentLocalName = localName break # More option values self.addOptionsValues() # End if not self.valid: mgear.log( "The guide doesn't seem to be up to date. Check logged messages and update the guide.", mgear.sev_warning) mgear.log("Guide loaded from hierarchy in [ " + "Not Yet Implemented" + " ]")
def setFromHierarchy(self, root): self.root = root self.model = self.root.getParent(generations=-1) # --------------------------------------------------- # First check and set the settings if not self.root.hasAttr("comp_type"): mgear.log("%s is not a proper guide."%self.root.longName(), mgear.sev_error) self.valid = False return self.setParamDefValuesFromProperty(self.root) # --------------------------------------------------- # Then get the objects for name in self.save_transform: if "#" in name: i = 0 while not self.minmax[name].max > 0 or i < self.minmax[name].max: localName = string.replaceSharpWithPadding(name, i) node = dag.findChild(self.model, self.getName(localName)) if not node: break self.tra[localName] = node.getMatrix(worldSpace=True) self.atra.append(node.getMatrix(worldSpace=True)) self.pos[localName] = node.getTranslation(space="world") self.apos.append(node.getTranslation(space="world")) i += 1 if i < self.minmax[name].min: mgear.log("Minimum of object requiered for "+name+" hasn't been reached", mgear.sev_warning) self.valid = False continue else: node = dag.findChild(self.model, self.getName(name)) if not node: mgear.log("Object missing : %s"%name, mgear.sev_warning) self.valid = False continue self.tra[name] = node.getMatrix(worldSpace=True) self.atra.append(node.getMatrix(worldSpace=True)) self.pos[name] = node.getTranslation(space="world") self.apos.append(node.getTranslation(space="world")) for name in self.save_blade: node = dag.findChild(self.model, self.getName(name)) if not node: mgear.log("Object missing : %s"%name, mgear.sev_warning) self.valid = False continue self.blades[name] = vec.Blade(node.getMatrix(worldSpace=True)) self.size = self.getSize()