Show Hidden

This macro shows hidden items. If the active doc is a part, it unhides hidden bodies. If the active doc is an assembly, it unhides hidden components.

The only credit I can take is finding other peoples code and mashing it together into this one macro. Any credit or blame goes to the unattributed original authors.

Private Declare PtrSafe Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
 
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim model As ModelDoc2
Dim part As PartDoc
Dim BodyArr As Variant
Dim swBody As Body2
 
Sub main()
 
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    If Not swModel Is Nothing Then
        
        Select Case swModel.GetType
            
            Case swDocPART:
                ShowPart
            
            Case swDocASSEMBLY:
                ShowAsm
                
            Case swDocDRAWING:
                MsgBox "This is a drawing. I don't work on drawings"
        End Select
        
    Else
        
        MsgBox "No document opened"
        
    End If
     
End Sub
 


Sub ShowPart()

Set part = swModel

BodyArr = part.GetBodies2(-1, False)

Dim Cnt As Integer

For Cnt = 0 To UBound(BodyArr)

    Set swBody = BodyArr(Cnt)

    If Not swBody Is Nothing Then

        swBody.HideBody (False)

    End If

Next Cnt
        
End Sub

Sub ShowAsm()
     Dim swAssy As SldWorks.AssemblyDoc
     
    
     Set swAssy = swApp.ActiveDoc
     
     If Not swAssy Is Nothing Then
     
        Dim swComp As SldWorks.Component2
        Set swComp = swAssy.SelectionManager.GetSelectedObjectsComponent3(1, -1)
        
        If swComp Is Nothing Then
            Set swComp = swAssy.ConfigurationManager.ActiveConfiguration.GetRootComponent3(False)
        End If
        
        ShowWithDependents swComp
        
     Else
        MsgBox "Please open assembly"
     End If
     
 End Sub

Sub ShowWithDependents(comp As SldWorks.Component2)
    
    comp.Select4 False, Nothing, False
    
    Const WM_COMMAND As Long = &H111
    Const SHOW_WITH_DEPENDENTS_CMD As Long = 33227
    
    Dim swFrame As SldWorks.Frame
    
    Set swFrame = swApp.Frame
    
    SendMessage swFrame.GetHWnd(), WM_COMMAND, SHOW_WITH_DEPENDENTS_CMD, 0
     
End Sub

It’s interesting that this only irritates and drives me crazy that there is no function for a sketch similar to parts and bodies: Hide others, Show all. <()>
This is especially annoying when in the drawing view you get a forest of sketches, and you only need one. I somehow couldn’t stand it and made a macro.
I originally wrote it for a drawing, but adapted it a little and it is also suitable for Parts and Assemblies models. If you select several sketches and run the macro, it will allow you to either hide or show all the unselected ones. I’ll leave it here.

There is also a start form that asks what to do, so I am attaching a macro file with an icon in the archive.
HideShowSketch.png

Hi Mihkow,
If I understand correctly, you actually have the option to hide the parts other than the ones I selected as an alternative in solid. Select the parts that I don’t want to hide, invert the selection, all parts except the one you selected will be selected and all will be hidden.

No, no, I’m not talking about Parts. I’m talking about Sketches.