def createMirrorCnxTemplate(model, in_controlers=None): cnx_prop = model.Properties(MIRROR_PROP_NAME) if not cnx_prop: cnx_prop = model.AddProperty("gear_Mirror", False, MIRROR_PROP_NAME) cnx_grid = cnx_prop.Parameters("CnxGridHidden").Value connections = par.getDictFromGridData(cnx_grid) if in_controlers is not None: controlers = XSIFactory.CreateObject("XSI.Collection") controlers.AddItems(in_controlers) cnx_grid.BeginEdit() pbar = uit.progressBar(controlers.Count, 1, "Creating Mirror Template", "", False) # Adding selected controlers to Connection map for ctl in controlers: pbar.StatusText = ctl.Name connections = addMirroringRule(ctl, cnx_grid, connections) pbar.Increment() pbar.Visible = False par.setDataGridFromDict(cnx_grid, connections) cnx_prop.Parameters("Count").Value = len(connections) cnx_grid.EndEdit() return cnx_grid
def gear_Mirror_SearchData_OnClicked(): cnx_grid = PPG.CnxGridHidden.Value connections = par.getDictFromGridData(cnx_grid) connections_display = searchRuleInDict(PPG.Search.Value, connections) cnxGrid_display = PPG.CnxGridDisplay.Value par.setDataGridFromDict(cnxGrid_display, connections_display)
def gear_Mirror_SearchSelected_OnClicked(): cnx_grid = PPG.CnxGridHidden.Value connections = par.getDictFromGridData(cnx_grid) connections_display = {} for ctl in xsi.Selection: connections_display.update(searchRuleInDict(ctl.Name + ".", connections)) cnxGrid_display = PPG.CnxGridDisplay.Value par.setDataGridFromDict(cnxGrid_display, connections_display)
def gear_Mirror_CnxGridDisplay_OnChanged(): cnx_grid = PPG.CnxGridHidden.Value cnxGrid_display = PPG.CnxGridDisplay.Value connections = par.getDictFromGridData(cnx_grid) connections_display = par.getDictFromGridData(cnxGrid_display) for k in connections_display: connections[k] = connections_display[k] par.setDataGridFromDict(cnx_grid, connections)
def gear_Mirror_SearchSelected_OnClicked(): cnx_grid = PPG.CnxGridHidden.Value connections = par.getDictFromGridData(cnx_grid) connections_display = {} for ctl in xsi.Selection: connections_display.update(searchRuleInDict(ctl.Name+".", connections)) cnxGrid_display = PPG.CnxGridDisplay.Value par.setDataGridFromDict(cnxGrid_display, connections_display)
def gear_Mirror_AddRule_OnClicked(): cnxGrid_display = PPG.CnxGridDisplay.Value cnx_grid = PPG.CnxGridHidden.Value connections_display = {} for ctl in xsi.Selection: connections = ani.addMirroringRule(ctl, cnx_grid) connections_display.update(searchRuleInDict(ctl.Name + ".", connections)) par.setDataGridFromDict(cnxGrid_display, connections_display) PPG.Count.Value = len(connections)
def gear_Mirror_AddRule_OnClicked(): cnxGrid_display = PPG.CnxGridDisplay.Value cnx_grid = PPG.CnxGridHidden.Value connections_display = {} for ctl in xsi.Selection: connections = ani.addMirroringRule(ctl, cnx_grid) connections_display.update(searchRuleInDict(ctl.Name+".", connections)) par.setDataGridFromDict(cnxGrid_display, connections_display) PPG.Count.Value = len(connections)
def addMirroringRule(ctl, cnx_grid, inversed_params=[], delUnused=False): model = ctl.Model # I want to get all the keyable parameters for this object and the easiest way # is to use the FindObjectsByMarkingAndCapabilities() method # but it only applies on collection controlers = XSIFactory.CreateObject("XSI.Collection") controlers.Add(ctl) key_params = controlers.FindObjectsByMarkingAndCapabilities(None, 2048) # try to find the mirror object mirror_ctl = model.FindChild(uti.convertRLName(ctl.Name)) connections = par.getDictFromGridData(cnx_grid) for param in key_params: # Skip marking set to avoid having all the params twice if param.Parent.Name == "MarkingSet" or param.Parent.Name.startswith( "DisplayInfo"): continue fullName = param.FullName[param.FullName.find(".") + 1:] # If the object mirror on itself, try to find R and L parameters if not mirror_ctl or mirror_ctl.IsEqualTo(ctl): mirror_param = param.Parent.Parameters( uti.convertRLName(param.Name)) if mirror_param: mirror_fullName = mirror_param.FullName[mirror_param.FullName. find(".") + 1:] else: mirror_fullName = fullName else: mirror_fullName = fullName.replace(ctl.Name, mirror_ctl.Name) if delUnused and (fullName == mirror_fullName and not param.FullName in inversed_params): continue connections[fullName] = [ mirror_fullName, param.FullName in inversed_params ] par.setDataGridFromDict(cnx_grid, connections) return connections
def gear_Mirror_DeleteRule_OnClicked(): cnxGrid_display = PPG.CnxGridDisplay.Value cnx_grid = PPG.CnxGridHidden.Value connections = par.getDictFromGridData(cnx_grid) connections_display = par.getDictFromGridData(cnxGrid_display) grid_widget = cnxGrid_display.GridWidget for i in range(cnxGrid_display.RowCount): if grid_widget.IsRowSelected(i): sKey = cnxGrid_display.GetRowValues(i)[0] connections_display.pop(sKey) connections.pop(sKey) par.setDataGridFromDict(cnxGrid_display, connections_display) par.setDataGridFromDict(cnx_grid, connections) PPG.Count.Value = len(connections)
def gear_Mirror_DeleteUnused_OnClicked(): cnx_grid = PPG.CnxGridHidden.Value cnxGrid_display = PPG.CnxGridDisplay.Value connections = par.getDictFromGridData(cnx_grid) connections_display = par.getDictFromGridData(cnxGrid_display) newConnections_hidden = {} for k in connections: if connections[k][1] or k != connections[k][0]: newConnections_hidden[k] = connections[k] else: if k in connections_display: connections_display.pop(k) par.setDataGridFromDict(cnxGrid_display, connections_display) par.setDataGridFromDict(cnx_grid, newConnections_hidden) PPG.Count.Value = len(newConnections_hidden)
def processComponents(self): import gear.xsi.rig.component as comp self.plog.reset(len(self.guides), 1) # Init self.components_infos = {} for guide in self.guides.values(): self.plog.log("Init", guide.fullName + " (" + guide.type + ")", True) module_name = "gear.xsi.rig.component." + guide.type module = __import__(module_name, globals(), locals(), ["*"], -1) Component = getattr(module, "Component") component = Component(self, guide) if component.fullName not in self.componentsIndex: self.components[component.fullName] = component self.componentsIndex.append(component.fullName) self.components_infos[component.fullName] = [ guide.compType, guide.getVersion(), guide.author ] par.setDataGridFromDict(self.components_grid, self.components_infos) # Creation steps self.steps = MainComponent.steps self.plog.reset(len(self.guides) * self.options["step"] + 1, 1) for i, name in enumerate(self.steps): for count, compName in enumerate(self.componentsIndex): component = self.components[compName] self.plog.log(name, component.fullName + " (" + component.type + ")", True) component.stepMethods[i]() xsi.Refresh() if self.options["step"] >= 0 and i >= self.options["step"]: break
def gear_Mirror_ImportRules_OnClicked(): cnx_grid = PPG.CnxGridHidden.Value # Parse XML file path = uit.fileBrowser("Import Mirroring Templates", xsi.ActiveProject2.OriginPath, "", ["xml"], False) if not path: return tree = etree.parse(path) root = tree.getroot() # Create Dictionary connections = {} for xml_cnx in root.findall("mirrorCnxMap/cnx"): connections[cnx.get("map_to")] = [xml_cnx.get("map_from"), xml_cnx.get("inv")] par.setDataGridFromDict(cnx_grid, connections) PPG.Count.Value = len(connections)
def gear_Mirror_ImportRules_OnClicked(): cnx_grid = PPG.CnxGridHidden.Value # Parse XML file path = uit.fileBrowser("Import Mirroring Templates", xsi.ActiveProject2.OriginPath, "", ["xml"], False) if not path: return tree = etree.parse(path) root = tree.getroot() # Create Dictionary connections = {} for xml_cnx in root.findall("mirrorCnxMap/cnx"): connections[xml_cnx.get("map_to")] = [xml_cnx.get("map_from"), xml_cnx.get("inv")] par.setDataGridFromDict(cnx_grid, connections) PPG.Count.Value = len(connections)
def addMirroringRule(ctl, cnx_grid, inversed_params=[], delUnused=False): model = ctl.Model # I want to get all the keyable parameters for this object and the easiest way # is to use the FindObjectsByMarkingAndCapabilities() method # but it only applies on collection controlers = XSIFactory.CreateObject("XSI.Collection") controlers.Add(ctl) key_params = controlers.FindObjectsByMarkingAndCapabilities(None, 2048) # try to find the mirror object mirror_ctl = model.FindChild(uti.convertRLName(ctl.Name)) connections = par.getDictFromGridData(cnx_grid) for param in key_params: # Skip marking set to avoid having all the params twice if param.Parent.Name == "MarkingSet" or param.Parent.Name.startswith("DisplayInfo"): continue fullName = param.FullName[param.FullName.find(".")+1:] # If the object mirror on itself, try to find R and L parameters if not mirror_ctl or mirror_ctl.IsEqualTo(ctl): mirror_param = param.Parent.Parameters(uti.convertRLName(param.Name)) if mirror_param: mirror_fullName = mirror_param.FullName[mirror_param.FullName.find(".")+1:] else: mirror_fullName = fullName else: mirror_fullName = fullName.replace(ctl.Name, mirror_ctl.Name) if delUnused and (fullName == mirror_fullName and not param.FullName in inversed_params): continue connections[fullName] = [mirror_fullName, param.FullName in inversed_params] par.setDataGridFromDict(cnx_grid, connections) return connections
def processComponents(self): import gear.xsi.rig.component as comp self.plog.reset(len(self.guides), 1) # Init self.components_infos = {} for guide in self.guides.values(): self.plog.log("Init", guide.fullName + " ("+guide.type+")", True) module_name = "gear.xsi.rig.component."+guide.type module = __import__(module_name, globals(), locals(), ["*"], -1) Component = getattr(module , "Component") component = Component(self, guide) if component.fullName not in self.componentsIndex: self.components[component.fullName] = component self.componentsIndex.append(component.fullName) self.components_infos[component.fullName] = [guide.compType, guide.getVersion(), guide.author] par.setDataGridFromDict(self.components_grid, self.components_infos) # Creation steps self.steps = MainComponent.steps self.plog.reset(len(self.guides) * self.options["step"]+1, 1) for i, name in enumerate(self.steps): for count, compName in enumerate(self.componentsIndex): component = self.components[compName] self.plog.log(name, component.fullName + " ("+component.type+")", True) component.stepMethods[i]() xsi.Refresh() if self.options["step"] >= 0 and i >= self.options["step"]: break