IBaseInterface to IIUnwrapMod

 
 
 
Posted by:Vincentt
Data created:20 September 2015

Hello,

I’m trying to use IIUnwrapMod but I’m having difficulties actually getting a hold of the object. The help says that I need to call the macro GetFPInter(f)ace(UNWRAP_INTERFACE). I’ve looked at this in the samples and it looks like this:

GetIUnwrapInterface(cd) \

(IUnwrapMod *)(cd)->GetInterface(UNWRAP_INTERFACE)

 

So I have the following C# code:

var UNWRAP_INTERFACE = GlobalInterface.Instance.Interface_ID.Create(0x53b3409b, 0x18ff7ab8); //taken from the iunwrap.h

var uvmapMod = (IModifier)GlobalInterface.Instance.COREInterface.CreateInstance(SClass_ID.Osm, GlobalInterface.Instance.Class_ID.Create(0x02df2e3a,0x72ba4e1f)); //Create new unwrap mod

var unwrapBaseInterface = (IIUnwrapMod)uvmapMod.GetInterface(UNWRAP_INTERFACE);

 

Unable to cast object of type 'Autodesk.Max.Wrappers.BaseInterface' to type 'Autodesk.Max.IIUnwrapMod'.

 

I also tried getting the Unwrap modifier from the object, instead of creating a new one:

var derivedObject= _node.ObjectRef as IIDerivedObject

IModifier unwrapMod = derivedObject.Modifiers[0];

 

I have tried the same code in C++ and it seems to work:

INode* node = ip->GetSelNode(0);

Object* pObject = node->GetObjectRef();

IDerivedObject* pDerivedObject = (IDerivedObject*)pObject;

Modifier* modifier = pDerivedObject->GetModifier(0);

 

//IUnwrapMod* unwrapMod =  GetIUnwrapInterface(modifier); //don’t have this macro in C#

IUnwrapMod* unwrapMod =  (IUnwrapMod *)(modifier)->GetInterface(UNWRAP_INTERFACE);

unwrapMod->fnOptions();

 

Any ideas what I can do here?

Thanks,
Vin

Hi Vin,

I checked the code and UNWRAP_INTERFACE is not upcast inside the GetInterface function which is why you're not getting the proper interface. The best I can do is try and make this working properly for next version of Max (2017). Would this work for you?

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Hey Marsel,

This is just for a personal project, so yeah, 2017 is fine. Thanks a lot!

 

Btw: is there any way I can check myself if something is not being upcasted? To avoid something like this in the future. 

Vin 

Ok, I will make the change. A way to check is to just try and cast it and see if you get an exception like you did.

Marsel Khadiyev (Software Developer, EPHERE Inc.)