Macro to toggle the sketch snapping in SOLIDWORKS document

Edit ArticleEdit Article
More 'Goodies'

Enable Sketch snapping option
Enable Sketch snapping option

This VBA macro allows to toggle on and off the 'Enable' option in SOLIDWORKS sketch.

Using macro in Toolbar+

This macro can be used in Toolbar+ which will improve the user experience. It is possible to enable the toggle state for the macro button.

Enable snapping toggle button
Enable snapping toggle button

Paste this code into the "Toggle Button State Code" text box:

Return CType(Application, Object).Sw.GetUserPreferenceToggle(249)

Code for handling the state of the toggle button
Code for handling the state of the toggle button

Download icon here

Dim swApp As SldWorks.SldWorks

Sub main()

    Set swApp = Application.SldWorks
    
    Dim curVal As Boolean
    curVal = False <> swApp.GetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchInference)
    
    swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swSketchInference, Not curVal
    
End Sub

Product of Xarial Product of Xarial