I want to get a .NET Element from a COM Element...
Element
using Bentley.DgnPlatformNET; using Bentley.DgnPlatformNET.Elements; using Bentley.MstnPlatformNET; using BCOM = Bentley.Interop.MicroStationDGN;
Element GetElementFromComElement (BCOM.Element oElement, bool addToModel) { if (addToModel) { BCOM.Application app = Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp; app.ActiveModelReference.AddElement(oElement); } IntPtr pointer = (IntPtr)oElement.MdlElementRef(); Element el = Element.GetFromElementRef(pointer); return el; }
If I call the above function with addToModel True, it works. If I call the function with addToModel False, it returns a null. But I don't want to write the COM element to file: I want an in-memory .NET Element. What's going on?
addToModel
I've marked this thread as solved, because a work-around exists. The question: 'Can we obtain a .NET Element from COM?' remains unanswered.
Hi Jon Summers,
Does populating the ModelRef via GetFromElementRefAndModelRef work and provide desired results?
e.g.
IntPtr elemRef = new IntPtr(interopElement.MdlElementRef()); IntPtr modelRef = new IntPtr(interopElement.ModelReference.MdlModelRefP()); return Bentley.DgnPlatformNET.Elements.Element.GetFromElementRefAndModelRef(elemRef, modelRef);
Bob