microstation sdk v8.11 - navigating programmatically through surface type 18

Dear all, good day.

I have a cell containing an element of type Surface(18).

I cannot understand how to navigate through its subelements.

Here it is visual basic code:

Public Sub NavigateThroughSurface(
   ByVal oApplication As Bentley.Interop.MicroStationDGN.Application
)
      Dim oEnumerator As Bentley.Interop.MicroStationDGN.ElementEnumerator = oApplication.ActiveModelReference.Scan      

      While oEnumerator.MoveNext
            Dim oElement = oEnumerator.Current
            If Not oElement.IsCellElement Then Continue While

            Dim oCellElement As Bentley.Interop.MicroStationDGN.CellElement = oElement.AsCellElement
            Dim lSubElementEnumerator As Bentley.Interop.MicroStationDGN.ElementEnumerator = oCellElement.GetSubElements
            While lSubElementEnumerator.MoveNext
                  Dim oSubElement = lSubElementEnumerator.Current
                  If oSubElement.Type = Bentley.Interop.MicroStationDGN.MsdElementType.Surface Then
                        'I do not find any "oSubElement.AsSurface" function...
                        'I have already done several tries, but without success:

                        '!!!!following statement throws exception:
                        Dim oBsplineSurfaceElement As Bentley.Interop.MicroStationDGN.BsplineSurfaceElement = oSubElement.AsBsplineSurfaceElement

                        '!!!!following statement throws exception too:
                        Dim lSolids As Bentley.Interop.MicroStationDGN.ElementEnumerator = oApplication.SmartSolid.ConvertToSmartSolidElement(oSubElement)

                        '?????????So how I can point to the surface itself and navigate through its subelements?????????
                  End If
            End While
      End While
End Sub

Thanks in advance.

Roberto

Italy

Parents Reply
  • I have tried both in vba and in vb.net, but it does not work.

    Following the link where you can download the very simple dgn file containing surface (type 18):

    https://app.box.com/s/6v0ksnpohoskaypskc7s4lmfa89cfe7j

    Here is the code in VBA:

    Option Explicit
    
    Public Sub Start()
        Dim oEnumerator As ElementEnumerator
        Set oEnumerator = Application.ActiveModelReference.Scan
        
        While oEnumerator.MoveNext
            Dim oElement As Element
            Set oElement = oEnumerator.Current
            
            If oElement.IsCellElement Then
                Dim oCellElement As CellElement
                Set oCellElement = oElement.AsCellElement
                
                Dim lSubElement As ElementEnumerator
                Set lSubElement = oCellElement.GetSubElements
                While lSubElement.MoveNext
                    Dim oSubElement As Element
                    Set oSubElement = lSubElement.Current
                    
                    Dim lSolid As ElementEnumerator
                    Set lSolid = Application.SmartSolid.ConvertToSmartSolidElement(oSubElement)
                    
                    MsgBox ("if you read this message, then it works!")
                Wend
            End If
                
        Wend
    End Sub

    This code throws following error:

    Here is the code in VB.net:

    Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
            Dim targetPWModel As String = "type1"
    
            Dim oApplicationObjectConnector As Bentley.Interop.MicroStationDGN.ApplicationObjectConnector = GetObject(, "MicroStationDGN.ApplicationObjectConnector")
            Dim oApplication = oApplicationObjectConnector.Application
    
            Dim oDesignFile = oApplication.ActiveDesignFile
    
            Dim oEnumerator As Bentley.Interop.MicroStationDGN.ElementEnumerator = oApplication.ActiveModelReference.Scan
            While oEnumerator.MoveNext
                Dim oElement = oEnumerator.Current
                If Not oElement.IsCellElement Then Continue While
    
                Dim oCellElement As Bentley.Interop.MicroStationDGN.CellElement = oElement.AsCellElement
                Dim lSubElementEnumerator As Bentley.Interop.MicroStationDGN.ElementEnumerator = oCellElement.GetSubElements
                While lSubElementEnumerator.MoveNext
                    Dim oSubElement = lSubElementEnumerator.Current
                    If oSubElement.Type = Bentley.Interop.MicroStationDGN.MsdElementType.Surface Then
                        'I do not find any "oSubElement.AsSurface" function...
                        'I have already done several tries, but without success:
    
                        Dim lSolids As Bentley.Interop.MicroStationDGN.ElementEnumerator = oApplication.SmartSolid.ConvertToSmartSolidElement(oSubElement)
    
                        MsgBox("if you read this message, then it works!")
                    End If
                End While
            End While
    
            MsgBox("done")
        End Sub

    And this is the error it throws:

    Any other ideas?

    Thanks again.

    Roberto

Children
  • This code throws following error

    CardosiEllipticalHead.dgn

    I simplified your DGN model (removed the cell) and VBA code...

    Option Explicit
    
    Public Sub Main()
        Dim id As DLong
        id = DLongFromLong(4090)
        Dim oHead As Element
        Set oHead = ActiveModelReference.GetElementByID(id)
        Debug.Assert Not oHead Is Nothing
        Analyse oHead
    End Sub
    
    Public Sub Analyse(ByVal oHead As Element)
        Dim oSolidComponents As ElementEnumerator
        ' Next line throws 'unknown error'
        Set oSolidComponents = SmartSolid.ConvertToSmartSolidElement(oHead)
        Debug.Assert Not oSolidComponents Is Nothing
        Do While oSolidComponents.MoveNext
            Debug.Print "Found component type " & _
               CStr(oSolidComponents.Current.Type)
        Loop
    
    End Sub
    

    The code fails to convert the Type 18 to a SmartSolid in the line below my comment.

    The DGN file and the VBA code provide evidence for a Trouble Report (TR) or Service Request (SR) you can file with Bentley Systems.  Or possibly  or can help?

     
    Regards, Jon Summers
    LA Solutions