def gear_MirrorAnimation_Execute(): # controlers if not xsi.Selection.Count: gear.log("No selection", gear.sev_error) return ## Miquel Shed added: else: controlers = XSIFactory.CreateActiveXObject("XSI.Collection") controlers.AddItems(xsi.Selection) ##end of the addition # Get First and Last Frame frames = fcv.getFirstAndLastKey(controlers) if not frames: gear.log("No Key on selection, cannot perform mirror animation", gear.sev_error) return # UI ui_prop = xsi.ActiveSceneRoot.AddProperty("CustomProperty", False, "Mirror Animation") pOffset = ui_prop.AddParameter3("offset", c.siInt4, 0, None, None, False, False) pConsiderTime = ui_prop.AddParameter3("considerTime", c.siBool, False, None, None, False, False) pFrameIn = ui_prop.AddParameter3("frameIn", c.siInt4, frames[0], None, None, False, False) pFrameOut = ui_prop.AddParameter3("frameOut", c.siInt4, frames[1], None, None, False, False) layout = ui_prop.PPGLayout layout.AddGroup("Options") layout.AddItem(pOffset.ScriptName, "Offset") layout.AddItem(pConsiderTime.ScriptName, "Consider Time") layout.AddRow() layout.AddItem(pFrameIn.ScriptName, "Frame In") layout.AddItem(pFrameOut.ScriptName, "Frame Out") layout.EndRow() layout.EndGroup() rtn = xsi.InspectObj(ui_prop, "", "Mirror Animation", c.siModal, False) frame_offset = pOffset.Value considerTime = pConsiderTime.Value frame_in = pFrameIn.Value frame_out = pFrameOut.Value xsi.DeleteObj(ui_prop) if rtn: return # Mirror ani.mirror(controlers, True, frame_offset, considerTime, frame_in, frame_out) 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
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