[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;
    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?

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
  • Hi ,

    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



Reply
  • Hi ,

    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



Children
No Data