[Microstation v8i, C#/C++] How to get the ElementRef and DgnModelRef from a C# API element?

I am trying to get the ElementRef and DgnModelRef from C# API of elements I have selected so I can pass through to some Native MDL code that needs to use them?

From searching through these community forums and browsing the C# functions/properties I have found Element.MdlElementRef() and Element.ModelReference.MdlModelRefp(). I believe these to be the equivalent of ElementRef and DgnModelRef respectively but they are not the same.

The functions return int's which when I get to the Native MDL I cannot find a way to use them to create the Ref types or use in place of the Ref types.

Is there a ideal way to get the appropriate Native MDL Ref types from what is available in the .Net API?

Parents
  • Unknown said:
    I am trying to get the ElementRef and DgnModelRef from MicroStation V8i C# API

    MicroStation V8 doesn't have a C# API.  You use the VBA (COM) API.  You can also use MDL via a Windows InterOp.

    Given a VBA Element instance, you can use these methods to get an ElementDescr or an ElementRef...

    • Element.MdlElementDescrP
    • Element.MdlElementRef

    Element.ModelReference gives you a VBA ModelReference...

    Element.ModelReference

    From which you can get an MDL DgnModelRefP...

    ModelReference.MdlModelRefP

     
    Regards, Jon Summers
    LA Solutions

  • Jon,

    Thanks for confirming my thoughts regarding Element.MdlElementRef and Element.ModelReference.MdlModelRefP.

    That was only the first part of my questions however, both of these functions return ints and ElementRef/DgnModelRef are structs. There is no immediately apparent way to me to create these structs from the int values and it is the structs that I need for other native MDL functions.

    Any ideas on how to do this?

  • Unknown said:
    Both of these functions return ints

    They return VBA Long, which is the only way in which VBA 6 can represent a 32-bit C pointer.

    If you're trying to write C# to get at MDL functions in V8i, then going via VBA is not a good route.  You lose information about the underlying data, and because VBA doesn't do pointers all you know is that you have a facsimile of a pointer to 'something'.  It's the equivalent of a void* in C.

    Unknown said:
    It is the structs that I need for other native MDL functions

    You're taking a rather elliptical route to achieve that goal.  Why not bite the bullet and write an MDL application?

    What are the benefits to you in using a language such as C# with no native API?  If you really need to stick with C#, then use MDL directly via an InterOp.  The MDL function manual provides a VBA Declare statement for each function.  You need to translate that into its .NET equivalent.  But then you must take care of issues such as memory management, which provide plenty of pitfalls before and after you start leaping over language boundaries.

     
    Regards, Jon Summers
    LA Solutions

  • Jon,

    Apologies for the delay I was not in the office on Friday, elliptical doesn't quite cover it, it is more akin a spiral or a helix.

    If it was as simple as choosing one API over the other I am not sure I'd be here asking questions, in short not one of the API's gives me everything I need.

    I have to use native MDL to get at the geometry I need through the use of ElementGraphicsProcessor and it is ProStructures element attribute data I am interested in retrieving which is only available through the ProStructures .Net API. I am not fussed which starting point I use whether it be an MDL command or .Net addin as long as I get the information I am after.

    The preference for C# is that our application is our own application is written in .Net making the interaction with that much easier and it doesn't make sense to me anyway to write a massive interop layer going from MDL to all the .Net when I have only one little thing I want from MDL.

    I realise I am no expert in the Bentley API's and what I know has come from my exposure to the help files or these forums.

    I am open to any suggestions.

    Nick
Reply
  • Jon,

    Apologies for the delay I was not in the office on Friday, elliptical doesn't quite cover it, it is more akin a spiral or a helix.

    If it was as simple as choosing one API over the other I am not sure I'd be here asking questions, in short not one of the API's gives me everything I need.

    I have to use native MDL to get at the geometry I need through the use of ElementGraphicsProcessor and it is ProStructures element attribute data I am interested in retrieving which is only available through the ProStructures .Net API. I am not fussed which starting point I use whether it be an MDL command or .Net addin as long as I get the information I am after.

    The preference for C# is that our application is our own application is written in .Net making the interaction with that much easier and it doesn't make sense to me anyway to write a massive interop layer going from MDL to all the .Net when I have only one little thing I want from MDL.

    I realise I am no expert in the Bentley API's and what I know has come from my exposure to the help files or these forums.

    I am open to any suggestions.

    Nick
Children
No Data