1 Reply Latest reply on Feb 21, 2018 2:46 PM by Jacob Corder

    Selecting Edges

    Martin M.

      Hi all, I copied this function from a different thread and I'm trying to convert it to select edges instead of faces. Everything works except for the line " Set Edge = Body.GetEdge ". How do I get GetEdge to work? The link to the other forum https://forum.solidworks.com/thread/213089


          Dim swApp As SldWorks.SldWorks

          Dim AssyDoc As SldWorks.ModelDoc2

          Dim longstatus As Long

          Dim MyMate As Object

          Dim CompName As String

          Dim EdgeName As String

          Dim CCompName As String

          Dim EEdgeName As String

          Dim boolstatus As Boolean

          Dim myComp1 As Component2

          Dim myComp2 As Component2

          Dim swAssy As SldWorks.AssemblyDoc

          Dim swComp As SldWorks.Component2

          Dim SelMgr As Object

          Dim SelData As SldWorks.SelectData

          Dim Comp As Object

          Dim Body As Object

          Dim Edge As SldWorks.Edge

          Dim CurEdgeName As String

          Const swSelCOMPONENTS = 20


      Public Sub SelectComponentEdgeByName(CompName As String, EdgeName As String)


          Set swApp = Application.SldWorks


          Set swModel = swApp.ActiveDoc


          Set SelMgr = swModel.SelectionManager()


          Set SelData = SelMgr.CreateSelectData


          Set Comp = swModel.GetComponentByName(CompName)


          Set Body = Comp.GetBody()


          If (Body Is Nothing) Then


              swApp.SendMsgToUser "Component Body Unavailable."


              swApp.SendMsgToUser "Make sure not lightweight or suppressed"


              Exit Sub


          End If


          Set Edge = Body.GetEdge


          Do While Not Edge Is Nothing


              CurEdgeName = swModel.GetEntityName(Edge)


              If (CurEdgeName = EdgeName) Then


                  boolstatus = Edge.Select4(True, SelData)


                  Exit Do


              End If


              Debug.Print CurEdgeName


              Set Edge = Edge.GetNextEdge




      End Sub