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