Notifications
Clear all

[Closed] How to pass a controller to the C#

 MZ1

How we can pass a controller to the C# function and cast it to the IControl class?

2 Replies

A Controller is an animatable, thus you can pass its ‘HandleByAnim’ to you C# method.
In C# you can retreive it:
IControl myCtrl = (IControl)global.Animatable.GetAnimByHandle(controllerHandle)
Haven’t tested but should work.

 MZ1

Thank You! It works:

public static class MyClass
{
    static IGlobal globalInterface = GlobalInterface.Instance;

    public static void GetValue(UIntPtr controlHandle)
    {
        IControl control = (IControl)globalInterface.Animatable.GetAnimByHandle(controlHandle);

        int time = globalInterface.COREInterface.Time;
        object val = null;
        val = 0.0f;
        control.GetValue(time, ref val, globalInterface.Interval.Create(), GetSetMethod.Relative);

        MessageBox.Show(val.ToString());
    }
}

just note that “GetHandleByAnim” is the correct function name. I really appreciate if you also take a look at my main question described here: Controller Callback
And tell is it possible to implement a OnValueChanged event raising for this controller?