VBA Macro to hide all sketches in the model using SOLIDWORKS API

Edit ArticleEdit Article
More 'Goodies'

This macro will hide (blank) or show (unblank) all sketches (2D and 3D) in the active document using SOLIDWORKS API.

Hide sketch option in context menu
Hide sketch option in context menu

Change HIDE_ALL_SKETCHES option to specify if sketches need to be hidden or shown.

Watch video demonstration

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Const HIDE_ALL_SKETCHES As Boolean = False 'True to hide all sketches, False to show all sketches

Const SKETCH_FEAT_TYPE_NAME As String = "ProfileFeature"
Const SKETCH_3D_FEAT_TYPE_NAME As String = "3DProfileFeature"

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    If Not swModel Is Nothing Then

        Dim swFeat As SldWorks.Feature
        Set swFeat = swModel.FirstFeature
        While Not swFeat Is Nothing
            If swFeat.GetTypeName2 = SKETCH_FEAT_TYPE_NAME Or _
                swFeat.GetTypeName2 = SKETCH_3D_FEAT_TYPE_NAME Then
                swFeat.Select2 False, -1
                If HIDE_ALL_SKETCHES Then
                End If
            End If
            Set swFeat = swFeat.GetNextFeature
        MsgBox "Please open part or assembly"
    End If
End Sub

Product of Xarial Product of Xarial