Hello
I wish I had the code to run "show with dependent" in solidworks 2018 SP5.
I found this link but the processing time is much longer than the "show with dependent" that you do manually in the SolidWorks feature manager.
http://help.solidworks.com/2015/english/api/sldworksapi/Show_All_Components_Example_VB.htm
Do you have any leads?
Thank you
Kind regards
Hello
You have to select the assembly and do a "ShowComponent2" on it, try the macro below (changing the name of the assembly "Assemblage1.SLDASM" to your own of course):
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Assemblage1.SLDASM", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Part.ShowComponent2
End Sub
Be careful, this only works on a parent assembly and on top-level components.
Kind regards
Hello D.Roger
Thank you for your answer.
I've already tried this code but indeed, it doesn't behave like the "show with dependents" which displays all the levels.
Here is the code that I found to be the fastest to run so far
Option Explicit
Public Enum swComponentVisibilityState_e
swComponentHidden = 0
swComponentVisible = 1
End Enum
Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long)
Dim vChildCompArr As Variant
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim swCompConfig As SldWorks.Configuration
Dim sPadStr As String
Dim i As Long
For i = 0 To nLevel - 1
sPadStr = sPadStr + " "
Next i
vChildCompArr = swComp.GetChildren
For Each vChildComp In vChildCompArr
Set swChildComp = vChildComp
Debug.Print sPadStr & swChildComp.Name2 & " <" & swChildComp.ReferencedConfiguration & ">"
If swComponentHidden = swChildComp.Visible Then
swChildComp.Visible = swComponentVisible
End If
TraverseComponent swChildComp, nLevel + 1
Next
End Sub
Sub montrer_tout()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swConf As SldWorks.Configuration
Dim swRootComp As SldWorks.Component2
Dim bRet As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent
Debug.Print "File = " & swModel.GetPathName
TraverseComponent swRootComp, 1
End Sub