Files
Lesson 3.4 homework part B solution
Code
'Homework 3.4b
'Create a macro that selects the adjacent edges of a selected vertex. Include error handling _
in the event that a vertex is not selected.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swVertex As SldWorks.Vertex
Dim swEdge As SldWorks.Edge
Dim swEnt As SldWorks.Entity
Dim vEdges As Variant
Dim i As Integer
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
'error handling in the event that a vertext is not selected
If swSelMgr.GetSelectedObjectType3(1, -1) <> swSelectType_e.swSelVERTICES Then
MsgBox "Please select a vertex."
End
End If
'get the selected vertex
Set swVertex = swSelMgr.GetSelectedObject6(1, -1)
'get the edges that meet at that vertex
vEdges = swVertex.GetEdges
'loop through the list of adjacent edges and select them
For i = 0 To UBound(vEdges)
Set swEdge = vEdges(i)
Set swEnt = swEdge
swEnt.Select4 True, Nothing
Next i
End Sub