[MS Connect Up12 - VBA] how to get reference clip Boundary

Hello,

I would like to get reference clip boundary in a MicroStation Connect VBA macro

Many thanks for your help

Rémy

  • Hi Remy,

    It has been a long time since I was dabbling with reference clips in MVBA, though I believe most of this code can be used as a starting point and help though it may need some minor tweaking to ensure it works in CONNECT to run and provide proper/expected results.

    Option Explicit
    #If VBA7 Then
        Declare PtrSafe Function mdlRefFile_getInfo Lib "stdmdlbltin.dll" (ByVal modelRef As Long) As Long
    #Else
        Declare Function mdlRefFile_getInfo Lib "stdmdlbltin.dll" (ByVal modelRef As Long) As Long
    #End If
    
    Private Const DISCONNECT = 1.79769313486231E+308                     'msdefs.h:327:#define DISCONNECT  (1.7976931348623157e308)
    Private Const Debug1 = True
    
    ...
    
    Sub ProcessAttachmentClips(oAtt As Attachment)
        
        ' Get reference clip pointer, else exit
        Dim ReferenceFileP As Long
        ReferenceFileP = mdlRefFile_getInfo(oAtt.MdlModelRefP)
        If ReferenceFileP = 0 Then Exit Sub
        
        ' Get reference clip count and pointer
        Dim elID As DLong
        Dim bIsDisconnect As Boolean, bIsStartPt As Boolean
        Dim oStartEndPt As Point2d, oDisconnect As Point2d
        Dim oPoint As Point3d
        Dim lShapeIdx As Long
        Dim lNumPoints As Long  ' < 4, or > 2500: MDLERR_INVALIDCLIP
        Dim strExpression As String, sMessage As String
        strExpression = "((struct referenceFile *)" & ReferenceFileP & ")"
        lNumPoints = GetCExpressionValue(strExpression & "->clip.clip_vertices")
        If Debug1 Then Debug.Print "NumPoints: " & lNumPoints & ", ElID: " & DLongToString(elID)
        oDisconnect = Point2dFromXY(DISCONNECT, DISCONNECT)
        
        ' Load point2d array with reference clip boundary and masks
        Dim I As Integer
        Dim arr() As Point2d, oCurrPt As Point2d
        ReDim arr(0 To lNumPoints)
        lShapeIdx = 0
        bIsStartPt = True
        For I = 0 To lNumPoints - 1
            ' Add current reference clip point to array
            arr(I).x = GetCExpressionValue(strExpression & "->clip.clipP[" & I & "].x")
            arr(I).Y = GetCExpressionValue(strExpression & "->clip.clipP[" & I & "].y")
            oCurrPt = arr(I)
            sMessage = ""
            ' Identify special points: Disconnect point and matching start and end points for clip masks.
            bIsDisconnect = Point2dEqual(oCurrPt, oDisconnect)
            If bIsDisconnect Then
                sMessage = "[DISCONNECT POINT]"
                bIsStartPt = True
                lShapeIdx = 0
            Else
                If bIsStartPt Then
                    oStartEndPt = oCurrPt
                End If
                bIsStartPt = Point2dEqual(oCurrPt, oStartEndPt)
                If bIsStartPt Then
                    lShapeIdx = lShapeIdx + 1
                    If (lShapeIdx Mod 2) = 0 Then
                        sMessage = "[END POINT]"
                        bIsStartPt = True
                        lShapeIdx = 0
                    Else
                        sMessage = "[START POINT]"
                        bIsStartPt = False
                    End If
                End If
                
                ' Print RAW clip point data
                Debug.Print vbTab & "RAW: " & MSUtils.Point3dToString(Point3dFromXY(oCurrPt.x, oCurrPt.Y))
    
                oPoint.x = oCurrPt.x / ActiveModelReference.UORsPerMasterUnit
                oPoint.Y = oCurrPt.Y / ActiveModelReference.UORsPerMasterUnit
    
                ' Print clip point transformed by ActiveModelRef UORsPerMasterUnit
                Debug.Print vbTab & "UORsPerMasterUnit: " & MSUtils.Point3dToString(oPoint)
                
                Dim oTransPt As Point3d
                Dim tMastToRef As Transform3d
                'tMastToRef = oAtt.GetReferenceToMasterTransform
                tMastToRef = oAtt.GetMasterToReferenceTransform
                oTransPt = Point3dFromTransform3dTimesPoint3d(tMastToRef, oPoint)
                'oTransPt.x = oPoint.x '/ ActiveModelReference.UORsPerMasterUnit
                'oTransPt.y = oPoint.y '/ ActiveModelReference.UORsPerMasterUnit
                ' Print clip point transformed by ActiveModelRef UORsPerMasterUnit
                Debug.Print vbTab & "MasterToReferenceTransform: " & MSUtils.Point3dToString(oTransPt)
                'CreatePointLine oTransPt 'oPoint
            End If
            Debug.Print "Point(" & I & ")" & vbTab & ".x: " & oCurrPt.x & ", .y: " & oCurrPt.Y & vbTab & sMessage
        Next
    
    End Sub

    HTH,
    Bob



  • Many thanks Robert and Jon

    After some attempt, and according to This topic

    It seems not so obvious to access to the members (in that case the clip object) of the reference file structure from connect edition VBA but I will continue to try

    Rémy