MACRO LIBRARY

Find a specified sketch point

Free public access. No account or subscription required.

Files

Find a specified sketch point

Code

'Precondition: sketch is selected in feature manager tree
'Result: see immediate window
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
'See notes for error
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSketch As SldWorks.Sketch
Dim swSkPt As SldWorks.SketchPoint
    
Dim vSkPts As Variant
Dim vSkPtCoords As Variant
Dim i As Integer
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    
    swModel.InsertSketch2 True
    swModel.ClearSelection2 True
    Set swSketch = swModel.GetActiveSketch2
    
    vSkPts = swSketch.GetSketchPoints2
    For i = 0 To UBound(vSkPts)
        Set swSkPt = vSkPts(i)
        'vSkPtCoords = swSkPt.GetCoords  'currently has a bug
        If Round(swSkPt.X, 3) = 0.03 And Round(swSkPt.Y, 3) = 0.03 And Round(swSkPt.Z, 3) = 0 Then
            Debug.Print "Point found!"
            swSkPt.Select4 True, Nothing
        End If
    Next i
End Sub
    
'Notes on NCE: if ISketchPoint::X, Y, and Z are not rounded, the conditional will yield false.
'NCE = non-critical error