'Get Sketch Points Example (VB)
'This example shows how to loop through the active sketch and extract the X,Y values of every sketch point.
'-----------------------------------------------
'
' Preconditions:
' (1) Document is open.
' (2) Editing a Sketch.
'
' Postconditions: None
'
'-----------------------------------------------
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim sketchPointArray As Variant
' Optional
Dim theSketchPoint As Object
Dim pointCount As Integer
Dim xValue As Double
Dim yValue As Double
Dim zValue As Double
Dim ExtraSpace As String
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set theSketch = swModel.GetActiveSketch2
sketchPointArray = theSketch.GetSketchPoints2
pointCount = UBound(sketchPointArray) + 1
' For each SketchPoint
For i = 0 To (pointCount - 1)
' Set local SketchPoint object (optional)
' Set theSketchPoint = sketchPointArray(i)
' Get the coordinates
xValue = sketchPointArray(i).X 'meters
yValue = sketchPointArray(i).Y 'meters
zValue = sketchPointArray(i).Z 'meters
Debug.Print "---------------------------"
If (xValue < 0) Then
ExtraSpace = ""
Else
ExtraSpace = " "
End If
Debug.Print "X: " & ExtraSpace & Format(xValue * 1000, "0.000000") & " [mm]"
If (yValue < 0) Then
ExtraSpace = ""
Else
ExtraSpace = " "
End If
Debug.Print "Y: " & ExtraSpace & Format(yValue * 1000, "0.000000") & " [mm]"
If (zValue < 0) Then
ExtraSpace = ""
Else
ExtraSpace = " "
End If
Debug.Print "Z: " & ExtraSpace & Format(zValue * 1000, "0.000000") & " [mm]"
' <Do something useful with the data>
Next i
End Sub