AnsweredAssumed Answered

Select Multiple surfaces by name - API

Question asked by Pichaiyan Prabaharan on Feb 14, 2021
Latest reply on Feb 16, 2021 by Pichaiyan Prabaharan


I tried to select multiple surfaces by its own name in assembly. I managed to select one surface. But unable to select second surface. Could you please help me on this?


  Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click

        Dim surface_1 As String = "A1"
        Dim surface_2 As String = "A2"
        Dim comp_1 As String = TextBox8.Text
        Dim comp_2 As String = TextBox9.Text
        Dim swModel As ModelDoc2

        swModel = swApp.ActiveDoc
        SelectSurface(swModel, surface_1, comp_1)
        SelectSurface(swModel, surface_2, comp_2)
    End Sub

Public Sub SelectSurface(ByRef swModel As ModelDoc2, ByRef surfaceName As String, ByRef compName As String)

        Dim swSelMgr As SelectionMgr
        Dim boolstatus As Long
        Dim swComp As Component2
        Dim swModelDocExt As ModelDocExtension
        Dim swFace As Face2
        Dim swBody As Body2
        Dim swSelData As SelectData

        swModel = swApp.ActiveDoc()
        swModelDocExt = swModel.Extension
        swSelMgr = swModel.SelectionManager
        boolstatus = swModelDocExt.SelectByID2(compName, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
        swComp = swSelMgr.GetSelectedObject6(1, -1)

        Dim currentFaceName As String
        swSelMgr = swModel.SelectionManager
        swSelData = swSelMgr.CreateSelectData

        swBody = swComp.GetBody()
        swFace = swBody.GetFirstFace
        Do While Not swFace Is Nothing
            currentFaceName = swModel.GetEntityName(swFace)
            If (currentFaceName = surfaceName) Then
                swFace.Select4(False, swSelData)
                Exit Do
            End If
            swFace = swFace.GetNextFace
    End Sub