def addLocMulti(self, name, parent, updateParent=True): """Add multiple loc objects to the guide. This method can initialize the object or draw it. Loc object is a simple null to define a position or a tranformation in the guide. Args: name (str): Local name of the element. parent (dagNode): The parent of the element. minimum (int): The minimum number of loc. maximum (int): The maximum number of loc. updateParent (bool): if True update the parent reference. False, keep the same for all loc. Returns: list of dagNode: The created loc objects in a list. """ if "#" not in name: mgear.log( "You need to put a '#' in the name of multiple location.", mgear.sev_error) return False locs = [] i = 0 while True: localName = string.replaceSharpWithPadding(name, i) if localName not in self.tra.keys(): break loc = icon.guideLocatorIcon(parent, self.getName(localName), color=17, m=self.tra[localName]) locs.append(loc) if updateParent: parent = loc i += 1 return locs
def modalPositions(self): """ Launch a modal dialog to set position of the guide. """ self.jNumberVal = False self.dirAxisVal = False self.jSpacVal = False for name in self.save_transform: if "#" in name: def _addLocMultiOptions(): pm.setParent(q=True) pm.columnLayout(adjustableColumn=True, cal="right") pm.text(l='', al="center") fl = pm.formLayout() jNumber = pm.intFieldGrp(v1=3, l="Joint Number") pm.setParent('..') pm.formLayout(fl, e=True, af=(jNumber, "left", -30)) dirSet = ["X", "-X", "Y", "-Y", "Z", "-Z"] fl = pm.formLayout() dirAxis = pm.optionMenu(l="Direction") dirAxis.addMenuItems(dirSet) pm.setParent('..') pm.formLayout(fl, e=True, af=(dirAxis, "left", 70)) fl = pm.formLayout() jSpac = pm.floatFieldGrp(v1=1.0, l="spacing") pm.setParent('..') pm.formLayout(fl, e=True, af=(jSpac, "left", -30)) pm.text(l='', al="center") pm.button(l='Continue', c=partial(_retriveOptions, jNumber, dirAxis, jSpac)) pm.setParent('..') def _retriveOptions(jNumber, dirAxis, jSpac, *args): self.jNumberVal = jNumber.getValue()[0] self.dirAxisVal = dirAxis.getValue() self.jSpacVal = jSpac.getValue()[0] pm.layoutDialog(dismiss="Continue") def _show(): pm.layoutDialog(ui=_addLocMultiOptions) _show() if self.jNumberVal: if self.dirAxisVal == "X": offVec = dt.Vector(self.jSpacVal, 0, 0) elif self.dirAxisVal == "-X": offVec = dt.Vector(self.jSpacVal * -1, 0, 0) elif self.dirAxisVal == "Y": offVec = dt.Vector(0, self.jSpacVal, 0) elif self.dirAxisVal == "-Y": offVec = dt.Vector(0, self.jSpacVal * -1, 0) elif self.dirAxisVal == "Z": offVec = dt.Vector(0, 0, self.jSpacVal) elif self.dirAxisVal == "-Z": offVec = dt.Vector(0, 0, self.jSpacVal * -1) newPosition = dt.Vector(0, 0, 0) for i in range(self.jNumberVal): newPosition = offVec + newPosition localName = string.replaceSharpWithPadding(name, i) self.tra[localName] = tra.getTransformFromPos( newPosition) return True
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): 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()