mdlMeasure_elmDscrArea : is this changed in connect version

if have this function that works in V8i version :

Private Function CalculateArea(ByRef area As Double, ByRef perimeter As Double, ByRef desc As Long) As Boolean
Dim cExpression As String
cExpression = "mdlMeasure_elmDscrArea(" & VarPtr(area) & "," & VarPtr(perimeter) & "," & desc & ")"
CalculateArea = (0 = GetCExpressionValue(cExpression))
End Function

when I try this in Connect version, it gives me the error "method 'getcexpressionvalue of object _application failed.

what can be wrong here ?

Parents
  • Please follow the MicroStation Programming forum best practices.

    Identify Your Programming Language

    It looks like you're writing MicroStation VBA and calling an MDL function using GetCExpressionValue?

    Code Syntax Highlighting

    When you post code, use the Forum advanced editor's syntax highlighting tool. That's the icon that resembles a pencil:  Syntax Highlighter

    Why call MDL when VBA includes measurement functions?

     
    Regards, Jon Summers
    LA Solutions

  • Correct, i'm using that getcexpressionValue in vba.  

    A bit of background : this function is part of old vba code (aprox 10 years old), that I'm trying to rework to c# (the program we writing is collecting data from microstation, office, illustrator, etc and store that in a database - kind of a program that holds all technical documentation in our company) .

     The information i need from microstation is the area, perimeter, ix, iy , ...  from profile drawings and send this to the database.    this code needs to be running without user interaction (only one click on a button) but also needs to run in batch over a bunch of drawings.  the old code to calculate works fine in select, but give's me errors in connect version. (when it calling that getcexpressionvalue function)

    I'm not aware of vba functions that calculates these kind of information ?

  • DgnPlatformNet API for C# Developers

    A bit of background : this function is part of old vba code (aprox 10 years old), that I'm trying to rework to c#

    MicroStation CONNECT provides the C# DgnPlatformNet API.  Having said that, I don't see any mention in the DgnPlatformNet help of a method to measure area or volume properties.  Perhaps someone from Bentley Systems can suggest how to achieve that.

    VBA ClosedElement Interface

    I'm not aware of VBA functions that calculates these kind of information ?

    VBA provides the ClosedElement interface.  If an element implements that interface then you can take measurements.

    There's also the Property Handler API, which may be useful to you.

    C Expressions in CONNECT

    You're not the first to notice that C Expressions don't work in CONNECT VBA.  C Expressions rely on some internal book-keeping where MDL functions were published in a way that they could be interpreted by the C Expression handler.  That internal book-keeping seems deficient.

    Reports, Tables and Item Types

    You should investigate Reports in CONNECT.  The report tools let you gather element information.  Once created, a report can be used to build a Table or sent to an external file such as CSV or XML.  By defining your own Item Types for business data, and attaching item data to graphical elements, you can add custom information to those reports.  In other words, you may not need to write any code.

    For example, here's an example of an AreaReport.

     
    Regards, Jon Summers
    LA Solutions

  • Hi,

    Unknown said:
    Correct, i'm using that getcexpressionValue in vba.

    May I ask why do you use GetCExpression? C expressions are usefull (better to say they were useful as they are connected with C API), but in my opinion there is no reason to use them in your situation.

    Why you don't call mdlMeasure_elmDscrArea directly? If it works in VBA (see code bellow) it can be used the same way in C#.

    Option Explicit
    
    Declare PtrSafe Function mdlMeasure_elmDscrArea Lib "stdmdlbltin.dll" (ByRef area As Double, ByRef perimeter As Double, ByVal edP As LongPtr) As Long
    
    Public Sub CalculateArea()
    
        Dim elem As Element
        Set elem = ActiveModelReference.GetElementByID(DLongFromLong(602))
        
        Dim elemRefP As LongPtr
        elemRefP = elem.MdlElementDescrP
        
        Dim area As Double
        Dim perimeter As Double
        
        Dim result As Long
        result = mdlMeasure_elmDscrArea(area, perimeter, elemRefP)
        
        If (0 = result) Then
            MsgBox "Area: " & CStr(area) & ", perimeter: " & CStr(perimeter)
        End If
    
    End Sub

    In fact a better solution would be to find a proper method in DgnPlatformNet, but I am not sure if such class / method exists.

    With regards,

      Jan

Reply
  • Hi,

    Unknown said:
    Correct, i'm using that getcexpressionValue in vba.

    May I ask why do you use GetCExpression? C expressions are usefull (better to say they were useful as they are connected with C API), but in my opinion there is no reason to use them in your situation.

    Why you don't call mdlMeasure_elmDscrArea directly? If it works in VBA (see code bellow) it can be used the same way in C#.

    Option Explicit
    
    Declare PtrSafe Function mdlMeasure_elmDscrArea Lib "stdmdlbltin.dll" (ByRef area As Double, ByRef perimeter As Double, ByVal edP As LongPtr) As Long
    
    Public Sub CalculateArea()
    
        Dim elem As Element
        Set elem = ActiveModelReference.GetElementByID(DLongFromLong(602))
        
        Dim elemRefP As LongPtr
        elemRefP = elem.MdlElementDescrP
        
        Dim area As Double
        Dim perimeter As Double
        
        Dim result As Long
        result = mdlMeasure_elmDscrArea(area, perimeter, elemRefP)
        
        If (0 = result) Then
            MsgBox "Area: " & CStr(area) & ", perimeter: " & CStr(perimeter)
        End If
    
    End Sub

    In fact a better solution would be to find a proper method in DgnPlatformNet, but I am not sure if such class / method exists.

    With regards,

      Jan

Children