I want to get a .NET Element from a COM Element...
using BCOM = Bentley.Interop.MicroStationDGN;
Element GetElementFromComElement (BCOM.Element oElement, bool addToModel)
BCOM.Application app = Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp;
IntPtr pointer = (IntPtr)oElement.MdlElementRef();
Element el = Element.GetFromElementRef(pointer);
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.
A whiIe back, I searched for the same thing and found this: https://communities.bentley.com/communities/other_communities/bdn_other_communities/w/chinabdn-wiki/41035/c-cli-addins - I guess, the code speaks for itself (or you could translate the rest with google or so). More importantly, it works. Provided that a small c++/cli helper lib is not off limits.. (Would be nice to have such function in the sdk)
Harmen große Deters said:A whiIe back, I searched for the same thing and found this
The same content, but in English, I linked in my earlier post.
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
My bad, I did not read you post carefully enough. (Also nice to have that blog post in English). An elemRef seems to be a reference to a persisted element, so the behavior Jon is describing is somehow logical. And Bobs example throws an AccesViolationException if the element is new.