C# Biped

C# Biped

MehdiZangenehBar
Advocate Advocate
893 Views
5 Replies
Message 1 of 6

C# Biped

MehdiZangenehBar
Advocate
Advocate

Anyone can show me how we can get biped interface inside C# using autodesk.max.dll? This is an example that GetInterface return null:

using System.Windows;
using Autodesk.Max;

namespace TestLibrary
{
    public static class TestClass
    {
        private readonly static IGlobal globalInterface = GlobalInterface.Instance;
        private readonly static IInterface coreInterface = globalInterface.COREInterface;

        public static void TestFunction()
        {
            IINode node = coreInterface.GetSelNode(0);
            IBipMaster iBipMaster = node.TMController.GetInterface((InterfaceID)0x9165) as IBipMaster;
            if (iBipMaster == null) MessageBox.Show("null");
        }
    }
}
0 Likes
894 Views
5 Replies
Replies (5)
Message 2 of 6

MehdiZangenehBar
Advocate
Advocate

Anyone has experience to use biped class in C#?

0 Likes
Message 3 of 6

Swordslayer
Advisor
Advisor

Type conversions in C# often have to be done via marshalling:

 

using Autodesk.Max.Wrappers;

...

public static Autodesk.Max.IBipMaster TestFunction()
{
	IINode node = coreInterface.GetSelNode(0);
	var ptr = ((INativeObject)node.TMController.GetInterface((InterfaceID)0x9167)).NativePointer;
	return (Autodesk.Max.IBipMaster)Autodesk.Max.Wrappers.CustomMarshalerBipMaster.GetInstance(string.Empty).MarshalNativeToManaged(ptr);
}

 

0 Likes
Message 4 of 6

MehdiZangenehBar
Advocate
Advocate

Which version do you use? I want to support 2018 and above. I'm looking for "IIBipMaster", not "IBipMaster".Based on your example, following code should work, right?

 

using System.Windows;
using Autodesk.Max;
using Autodesk.Max.Wrappers;

namespace TestLibrary
{
    public static class TestClass
    {
        private readonly static IGlobal globalInterface = GlobalInterface.Instance;
        private readonly static IInterface coreInterface = globalInterface.COREInterface;

        public static void TestFunction()
        {
            IINode node = coreInterface.GetSelNode(0);
            var ptr = ((INativeObject)node.TMController.GetInterface((InterfaceID)0x9167)).NativePointer;
            IIBipMaster bipInterface = (IIBipMaster)CustomMarshalerBipMaster.GetInstance(string.Empty).MarshalNativeToManaged(ptr);
            MessageBox.Show(bipInterface.NumFingers.ToString());
        }
    }
}

 

 

 

But it will crash the max.

0 Likes
Message 5 of 6

MehdiZangenehBar
Advocate
Advocate

I found this solution from the biped API:

using System.Windows;
using Autodesk.Max;

namespace TestLibrary
{
    public static class TestClass
    {
        private readonly static IGlobal globalInterface = GlobalInterface.Instance;
        private readonly static IInterface coreInterface = globalInterface.COREInterface;

        public static void TestFunction()
        {
            IINode node = coreInterface.GetSelNode(0);
            IIBipMaster bipInterface = globalInterface.IBipMaster12.GetBipMaster12Interface(node.TMController);
            MessageBox.Show(bipInterface.NumFingers.ToString());
        }
    }
}

But I just wondering why IBipMaster API is not exist in the GlobalInterface, like this:

IIBipMaster bipInterface = globalInterface.IBipMaster.GetBipMasterInterface(node.TMController);
0 Likes
Message 6 of 6

Swordslayer
Advisor
Advisor

You had IBipMaster in your original code so I gave you that. Anyway, change CustomMarshalerBipMaster to CustomMarshalerIBipMaster and you should be there (works as expected in 2021).

0 Likes