[CONNECT .NET] Get In-Memory Element from COM Impossible

I want to get a .NET Element from a COM 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;
  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?

I've marked this thread as solved, because a work-around exists.  The question: 'Can we obtain a .NET Element from COM?' remains unanswered.

Parents Reply
  • you posted your question to a wrong forum

    Oops!  Thanks for pointing that out.

    I think you cannot expect pointer from COM is the same as pointer from NET

    It's an ElementRef pointer that is used: the code gets that  pointer from COM, then uses it in .NET.  As shared by  in his csAddIns project.

    IntPtr pointer = (IntPtr)oElement.MdlElementRef();

    So why does that COM function exist if the pointer it obtains cannot be used anywhere?


    Why does that function exist if it can't construct a .NET Element from an ElementRef pointer?

    Regards, Jon Summers
    LA Solutions