SolidWorks's API help is still very comprehensive, there are a lot of simple and effective procedures, and it is bubble in the API help. It is now getting faster. It seems that the feeling of being recorded in Excel during the year. The following program is in the API help, which is used to display all parts of the ligand. I used my colleagues that they felt good :). The program uses a simple recursive method to traverse the assembly.
Make All Assembly Components Visible Example (VB)
This Example Shows How To make All assembly company.
'---------------------------------------
'
'Preconditions: an assembly document is open.
'
'Postconditions: Any Hidden Assembly Components Are Made Visible.
'
'---------------------------------------
Option expedition
Public Enum SwcomponentVisibilityState_e
Swcomponenthidden = 0
SWComponentVisible = 1
END ENUM
Sub TraveseComponent_
(_ _
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 swichildcomp = vchildcomp
Debug.print spadstr & swchildcomp.name2 & "<" & swchildcomp.referencedConfiguration & ">"
IF swcomponenthidden = swchildcomp.visible the
SWCHILDCOMP.Visible = SWComponentvisible
END IF
TraverseComponent Swchildcomp, NLEVEL 1
NEXT
End Sub
Sub main ()
DIM SWAPP
As SLDWorks.SldWorks
DIM SWMODEL
As SLDWORKS.MODELDOC2
DIM SWASSY
As SLDWORKS.ASSEMBLYDOC
DIM SWCONF
As SLDWorks.configuration
DIM SWROTCOMP
As SLDWORKS.Component2
DIM BRET
As boolean
Set swapp = application.sldworks
Set swymodel = swapp.activedoc
Set swconf = swmodel.getactiveconfigurationSet swrootcomp = swconf.getrootcomponent
Debug.print "File =" & SWModel.getPathname
TraverseComponent Swrootcomp, 1
End Sub