MACRO LIBRARY

Dissolve all component library features in assembly

Free public access. No account or subscription required.

Files

Dissolve all component library features in assembly

Code

'Dissolve all library features in an assembly
    
'Preconditions: assembly is open
'Result: library features are dissolved at part level
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swComp As SldWorks.Component2
Dim swCompModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim i As Integer
Dim vComps As Variant
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swAssy = swModel
    vComps = swAssy.GetComponents(False)
    For i = 0 To UBound(vComps)
        Set swComp = vComps(i)
        Set swCompModel = swComp.GetModelDoc2
        If swCompModel.GetType = swDocPART Then
            Set swFeat = swCompModel.FirstFeature
            While Not swFeat Is Nothing
                If swFeat.GetTypeName = "LibraryFeature" Then
                    Debug.Print swFeat.Select2(False, 0)
                    Debug.Print swCompModel.DissolveLibraryFeature
                End If
                Set swFeat = swFeat.GetNextFeature
            Wend
        End If
    Next i
End Sub