Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Use PainterInterface in DotNet

Use PainterInterface in DotNet

Anonymous
Not applicable
915 Views
4 Replies
Message 1 of 5

Use PainterInterface in DotNet

Anonymous
Not applicable

Hello,

 

Im trying to find a way to get the PainterInterface instance in mt DotNet plugin. Here's my code : 

 

public static IInterface_ID PAINTERINTERFACEV5_INTERFACE
{
  get
  {
    return Global.Interface_ID.Create(0x53b4520c, 0x29ff7ac9);
  }
}

public static IIPainterInterface_V5 PainterInterface
{
  get
  {
    IReferenceTarget painterRef = Ip.CreateInstance(PAINTERINTERFACE_SUPERCLASS_ID, PAINTERINTERFACE_CLASS_ID) as IReferenceTarget;
    if (painterRef != null)
    {
      IBaseInterface interf = painterRef.GetInterface(PAINTERINTERFACEV5_INTERFACE); // is non-null
return (IIPainterInterface_V5)interf; // return null } return null; } } public static uint PAINTERINTERFACE_V5 { get { return 0x78ffe181; } } public static uint PAINTERCANVASINTERFACE_V5 { get { return 0x29ff7ac9; } } public static SClass_ID PAINTERINTERFACE_SUPERCLASS_ID { get { return SClass_ID.RefTarget; } } public static IClass_ID PAINTERINTERFACE_CLASS_ID { get { return Global.Class_ID.Create(0x2f2ef7e9, PAINTERINTERFACE_V5); } }

It seems when I cast my BaseInterface to IIPainterInterface_V5, the object becomes null, maybe i missed something...

 

Thank you.

0 Likes
Accepted solutions (1)
916 Views
4 Replies
Replies (4)
Message 2 of 5

denisT.MaxDoctor
Advisor
Advisor

i'm a c++ programmer but my guess is it should be just:

 

IIPainterInterface_V5 interf = (IIPainterInterface_V5)painterRef.GetInterface(PAINTERINTERFACEV5_INTERFACE);
0 Likes
Message 3 of 5

Anonymous
Not applicable

 

@Anonymous wrote:

i'm a c++ programmer but my guess is it should be just:

 

IIPainterInterface_V5 interf = (IIPainterInterface_V5)painterRef.GetInterface(PAINTERINTERFACEV5_INTERFACE);

I splitted the interf declaration in two lines to see it was the cast which causes the issue. when i wrote the same line as yours, the result is null too unfortunately.

0 Likes
Message 4 of 5

denisT.MaxDoctor
Advisor
Advisor

Here is what I do and it works:

(for example)

 

BOOL BringUpPainterOptions()
{
	ReferenceTarget *painterRef = (ReferenceTarget*)GetCOREInterface()->CreateInstance(REF_TARGET_CLASS_ID, PAINTERINTERFACE_CLASS_ID);	
	if (painterRef) 
	{
		//set it to the correct verion
		IPainterInterface_V5* pPainter = (IPainterInterface_V5*)painterRef->GetInterface(PAINTERINTERFACE_V5);
		return pPainter->BringUpOptions();
	}
	return FALSE;
}

 

according to the documentation

class IPainterInterface_V5: public MaxHeapOperators
	{

this interface doesn't derive from BaseInterface, so the casting to it doesn't make sense

0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

@Anonymous wrote:

Here is what I do and it works:

(for example)

 

BOOL BringUpPainterOptions()
{
	ReferenceTarget *painterRef = (ReferenceTarget*)GetCOREInterface()->CreateInstance(REF_TARGET_CLASS_ID, PAINTERINTERFACE_CLASS_ID);	
	if (painterRef) 
	{
		//set it to the correct verion
		IPainterInterface_V5* pPainter = (IPainterInterface_V5*)painterRef->GetInterface(PAINTERINTERFACE_V5);
		return pPainter->BringUpOptions();
	}
	return FALSE;
}

 

according to the documentation

class IPainterInterface_V5: public MaxHeapOperators
	{

this interface doesn't derive from BaseInterface, so the casting to it doesn't make sense


Indeed there are two differents methods for GetInterface from IAnimatable, one returns an IBaseInterface, the other an object (same as "void *").  The last one needs an InterfaceID enumerator as parameter, but here is the list of enumerators given by 3dsMax : 

 

public enum InterfaceID
    {
        Control = 4112,
        Ikcontrol = 4128,
        Ikchaincontrol = 4144,
        Wirecontrol = 4160,
        Scriptcontrol = 4176,
        Master = 4192,
        Easelist = 4208,
        Multlist = 4224,
        Baseobject = 4240,
        Wsmobject = 4256,
        Derivedobject = 4272,
        Object = 4288,
        Particleobj = 4304,
        Lightobj = 4320,
        Simpleparticleobj = 4336,
        Keycontrol = 4352,
        Keycontrol2 = 4368,
        Setkeycontrol = 4384,
        SystemXref = 4400,
        Textobject = 4416,
        Wavesound = 4432,
        Newpartpod = 4464,
        Newpartsource = 4480,
        Newpartoperator = 4496,
        Newparttest = 4512,
        Meshselect = 4528,
        Meshselectdata = 4544,
        Maxscriptplugin = 4560,
        Meshdeltauser = 4576,
        Meshdeltauserdata = 4592,
        Splineselect = 4608,
        Splineselectdata = 4624,
        Splineops = 4640,
        Patchselect = 4656,
        Patchselectdata = 4672,
        Patchops = 4688,
        Submap = 4704,
        Mitranslator = 4720,
        Mentalray = 4736,
        Newmtlinterface = 4752,
        Component = 4768,
        Refarray = 4784,
        Linktmctrl = 4800,
        Subtargetctrl = 4816,
        Reagent = 4832,
        Geomimp = 4848,
        Aggregation = 4864,
        Valence = 4880,
        Guest = 4896,
        Host = 4912,
        Sceneobject = 4928,
        Multitangent = 4944,
        Softselect = 4960,
        Unreplaceablectl = 4976,
        Eulerctrl = 4992,
        Locked = 5008,
        LockedClient = 5024,
        ObjectsuperclassNotObjectclass = 5040,
        Compositesubmtlapi = 5056,
        Mtlidset = 5072,
        Userinterface = 65535
    }

In C++ we use PAINTERINTERFACE_V5 (0x78ffe181), so i also tried to cast this unsigned integer as InterfaceID...

The object returned is an NativeObject instance (from unmanaged memory) and it can't be cast directly too, so i used Marshal module to get the interface from the native object.

 

IReferenceTarget painterRef = (IReferenceTarget)Ip.CreateInstance(PAINTERINTERFACE_SUPERCLASS_ID, PAINTERINTERFACE_CLASS_ID);
if (painterRef != null)
{
  InterfaceID PainterInterfaceID = (InterfaceID)PAINTERINTERFACE_V5;
  Autodesk.Max.Wrappers.NativeObject obj = painterRef.GetInterface(PainterInterfaceID) as Autodesk.Max.Wrappers.NativeObject;
  IIPainterInterface_V5 pi = Global.IPainterInterface_V5.Marshal(obj.NativePointer);
  return pi;
}

It seems to work this way,

thank you !

 

0 Likes