Get Vertex Example (VBA)
This example shows how to get the x,y,z location
of each vertex on the selected face:
Query a face for edge
information
Traverse the topology
of a part from the face down to the vertex
Determine the selected
object count
Get objects selected
by the user
Determine object types
'------------------------------------------------------------
Public Sub GetEndPoints()
Dim i As Long
Dim
Msg As String
Dim Style As Variant
Dim Title As String
Dim swApp, Part,
SelMgr As Object
Dim faceObj
As Object
Dim edgeList
As Variant
Dim edgeCount
As Long
Dim edgeObj
As Object
Dim startVertexObj
As Object
Dim endVertexObj
As Object
Dim startPt
As Variant
Dim endPt As
Variant
Set swApp =
CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Set SelMgr =
Part.SelectionManager
If (SelMgr.GetSelectedObjectCount = 0) Then
swApp.SendMsgToUser ("Select a face first...")
Else
If (SelMgr.GetSelectedObjectType(1) <> 2)
Then
swApp.SendMsgToUser ("Must select a face")
Exit Sub
End If
Set faceObj
= SelMgr.GetSelectedObject5(1)
edgeCount =
faceObj.GetEdgeCount
edgeList = faceObj.GetEdges
For i = 0 To
(edgeCount - 1)
Set edgeObj
= edgeList(i)
Set startVertexObj
= edgeObj.GetStartVertex
Set endVertexObj
= edgeObj.GetEndVertex
Msg = "Edge
points: " + Chr(10)
If (Not startVertexObj
Is Nothing) Then
startPt = startVertexObj.GetPoint
Msg = Msg +
Str$(startPt(0))+","+Str$(startPt(1))+","+Str$(startPt(2))+Chr(10)
End If
If (Not endVertexObj
Is Nothing) Then
endPt = endVertexObj.GetPoint
Msg = Msg +
Str$(endPt(0))+","+Str$(endPt(1))+","+Str$(endPt(2))
End If
Style = vbOKOnly
Title = "Vertex
Info"
Call MsgBox(Msg,
Style, Title)
Next
End If
End Sub