Casting GeomObject to PolyObject or TriObject

 
 
 
Posted by:antoine
Data created:29 May 2010

Hey !

Casting GeomObject to PolyObject or TriObject invariably gives me an exception:

System.InvalidCastException: Unable to cast object of type 'Autodesk.Max.Wrappers.GeomObject' to type 'Autodesk.Max.IPolyObject'.

My code:

 IPolyObject polyObj = (IPolyObject)node.EvalWorldState(0, true).Obj.ConvertToType(0, global.PolyObjectClassID);

Same thing for triobjects.

Am I missing something ?

Cheers

Antoine.

Looks like it should work, I just checked the code and it should upcast the object properly to TriObj if its ClassID is ::Class_ID( TRIOBJ_CLASS_ID, 0 ) or PolyObject for ::Class_ID( POLYOBJ_CLASS_ID, 0 ).

Can you please check the ClassID returned by the object you're trying to cast (ie. provide me with value of node.EvalWorldState(0, true).Obj.ConvertToType(0, global.PolyObjectClassID).ClassID.PartA and PartB)?

Thanks

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Wow, that was fast :)

Sure, PartA is 469250957,

PartB is 422535320.

Thx !!

Aha, #define EPOLYOBJ_CLASS_ID Class_ID(0x1bf8338d,0x192f6098), I did not specify that for the upcast. This should be fixed in the next build.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Great News !

In case of upcasting a GeomObject to a triObject, the classID is the following (my object is an editable mesh in that case):

PartA:3830386867

PartB:0

Thanks again.

Antoine.