Example #1
0
def applyAction(model, action_name, controlers=None):

    mixer = mix.Mixer(model)

    if action_name not in mixer.animSources.keys():
        gear.log("Can't find action : " + action_name, gear.sev_error)

    action = mixer.animSources[action_name].value

    if controlers is not None:
        keyable_params = [
            param.FullName for param in getKeyableParameters(controlers)
        ]
        import gear
        gear.log(keyable_params)

        for item in action.SourceItems:
            if model.FullName + "." + item.Target in keyable_params:
                item.Active = True
            else:
                item.Active = False
    else:
        for item in action.SourceItems:
            item.Active = True

    xsi.ApplyAction(action, model)
Example #2
0
File: logic.py Project: jeanim/gear
def plotSpringToControler(comp_name, prop):

    # Get objects
    model = prop.Model
    refs = []
    ctls = []
    i = 0
    while True:
        ctl = model.FindChild(comp_name + "_fk%s_ctl" % i)
        ref = model.FindChild(comp_name + "_%s_ref" % i)

        if not ctl or not ref:
            break

        ctls.append(ctl)
        refs.append(ref)

        i += 1

    # UI
    pc = ani.PlayControl()
    ui_prop = xsi.ActiveSceneRoot.AddProperty("CustomProperty", False, "Plot")
    pStartFrame = ui_prop.AddParameter3("start_frame", c.siInt4,
                                        pc.localIn.Value, None, None)
    pEndFrame = ui_prop.AddParameter3("end_frame", c.siInt4, pc.localOut.Value,
                                      None, None)

    rtn = xsi.InspectObj(ui_prop, "", "Plot", c.siModal, False)

    start_frame = pStartFrame.Value
    end_frame = pEndFrame.Value

    xsi.DeleteObj(ui_prop)

    if rtn:
        return

    # Plot
    params = [
        ref.Kinematics.Local.Parameters("rot" + s).FullName for ref in refs
        for s in "xyz"
    ]
    action = xsi.PlotAndApplyActions(",".join(params), "plot", start_frame,
                                     end_frame, 1, 20, 3, False, .01, True,
                                     False, False, False)(0)

    # Edit the stored Action
    for item in action.SourceItems:

        item.Target = item.Target.replace(comp_name + "_", comp_name + "_fk")
        item.Target = item.Target.replace("_ref", "_ctl")

    prop.Parameters(comp_name + "_main_blend").Value = 0
    xsi.ApplyAction(action)
    xsi.DeleteObj(action)
Example #3
0
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