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 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_ExportRules_OnClicked(): model = PPG.Inspected(0).Model cnx_grid = PPG.CnxGridHidden.Value connections = par.getDictFromGridData(cnx_grid) # Parse XML file -------------------------------- path = uit.fileBrowser("Export Mirroring Templates", xsi.ActiveProject2.OriginPath, model.Name, ["xml"], True) if not path: return # Create Root structure xml_root = etree.Element("mirrorTemplates", version="1.0", comment="Mapping rules for gear_MirrorAnimation plugin") # Infos xml_infos = etree.SubElement(xml_root, "infos", model=model.Name, count=str(len(connections))) xml_cnxMap = etree.SubElement(xml_root, "mirrorCnxMap") # Export CnxMap keys = connections.keys() keys.sort() for k in keys: etree.SubElement(xml_cnxMap, "cnx", map_from=k, map_to=connections[k][0], inv=str(connections[k][1])) xmldom.indent(xml_root) tree = etree.ElementTree(xml_root) tree.write(path)
def gear_Mirror_ExportRules_OnClicked(): model = PPG.Inspected(0).Model cnx_grid = PPG.CnxGridHidden.Value connections = par.getDictFromGridData(cnx_grid) # Parse XML file -------------------------------- path = uit.fileBrowser("Export Mirroring Templates", xsi.ActiveProject2.OriginPath, model.Name, ["xml"], True) if not path: return # Create Root structure xml_root = etree.Element("mirrorTemplates", version="1.0", comment="Mapping rules for gear_MirrorAnimation plugin") # Infos xml_infos = etree.SubElement(xml_root, "infos", model=model.Name, count=str(len(connections))) xml_cnxMap = etree.SubElement(xml_root, "mirrorCnxMap") # Export CnxMap keys = connections.keys() keys.sort() for k in keys: etree.SubElement(xml_cnxMap, "cnx", map_from=k, map_to=connections[k][0], inv=str(connections[k][1])) xmldom.indent(root) tree = etree.ElementTree(xml_root) tree.write(path)
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 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_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 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 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 mirror(controlers=xsi.Selection, animation=False, frame_offset=0, considerTime=False, frame_in=0, frame_out=0): if not animation: source_type = 1 considerTime = False frame_offset = 0 else: source_type = 6 params = getKeyableParameters(controlers) # Avoid having the parameter and its proxy in the collection # Curiosly, XSI can store the fcurves of the parameter and its proxy separatly # We get weird result when applying the action key_params = XSIFactory.CreateObject("XSI.Collection") key_params.Unique = True for param in params: if param.Type == "ProxyParameter": key_params.Add(param.MasterParameter) else: key_params.Add(param) if not key_params.Count: gear.log("No Keyable Parameter on Selection", gear.sev_error) return # Get all keys if considerTime is False if not considerTime and animation: frame_in, frame_out = fcu.getFirstAndLastKey(controlers) # Get Connexion Map -------------------- model = controlers(0).Model cnx_prop = model.Properties(MIRROR_PROP_NAME) if not cnx_prop: gear.log("There is no Mirror Cnx Template on this model", gear.sev_error) return cnx_grid = cnx_prop.Parameters("CnxGridHidden").Value connections = par.getDictFromGridData(cnx_grid) # Actions ------------------------------ # Store the Action if model.Sources("Temp_MirrorAction"): xsi.DeleteObj(model.Sources("Temp_MirrorAction")) action = xsi.StoreAction(model, key_params, source_type, "Temp_MirrorAction", False, frame_in, frame_out, considerTime, False, False, False) # Edit the stored Action for item in action.SourceItems: # skip sourceItems if not listed in the CnxMap if item.Target not in connections: continue # Change the target to mirror action target = connections[item.Target] item.Target = target[0] # Inverse the value of fcurve if necessary # The string version is to keep compatibility with previous version of XSI # When the gridata was only returning string if target[1] in [True, "True"]: invertSource(item.Source) xsi.ApplyAction(action, model, True, frame_in + frame_offset, frame_out + frame_offset, False) xsi.DeleteObj(action) return
def mirror(controlers=xsi.Selection, animation=False, frame_offset=0, considerTime=False, frame_in=0, frame_out=0): if not animation: source_type = 1 considerTime = False frame_offset = 0 else: source_type = 6 params = getKeyableParameters(controlers) # Avoid having the parameter and its proxy in the collection # Curiosly, XSI can store the fcurves of the parameter and its proxy separatly # We get weird result when applying the action key_params = XSIFactory.CreateObject("XSI.Collection") key_params.Unique = True for param in params: if param.Type == "ProxyParameter": key_params.Add(param.MasterParameter) else: key_params.Add(param) if not key_params.Count: gear.log("No Keyable Parameter on Selection", gear.sev_error) return # Get all keys if considerTime is False if not considerTime and animation: frame_in, frame_out = fcu.getFirstAndLastKey(controlers) # Get Connexion Map -------------------- model = controlers(0).Model cnx_prop = model.Properties(MIRROR_PROP_NAME) if not cnx_prop: gear.log("There is no Mirror Cnx Template on this model", gear.sev_error) return cnx_grid = cnx_prop.Parameters("CnxGridHidden").Value connections = par.getDictFromGridData(cnx_grid) # Actions ------------------------------ # Store the Action if model.Sources("Temp_MirrorAction"): xsi.DeleteObj(model.Sources("Temp_MirrorAction")) action = xsi.StoreAction(model, key_params, source_type, "Temp_MirrorAction", False, frame_in, frame_out, considerTime, False, False, False) # Edit the stored Action for item in action.SourceItems: # skip sourceItems if not listed in the CnxMap if item.Target not in connections: continue # Change the target to mirror action target = connections[item.Target] item.Target = target[0] # Inverse the value of fcurve if necessary # The string version is to keep compatibility with previous version of XSI # When the gridata was only returning string if target[1] in [True, "True"]: invertSource(item.Source) xsi.ApplyAction(action, model, True, frame_in+frame_offset, frame_out+frame_offset, False) xsi.DeleteObj(action) return