Break down a multi-level assembly into 1 level using a macro

Hello everyone,

In one of my cases I have an assembly with 3 sub-assemblies at the 1st level at the 2nd level part + sub-assembly.I have 5 levels

I use the function Break Up a Subassembly

I would like to put all my parts files on the 1st level. (no sub-assembly feature in the main assembly) I use SW2017

Is there a macro to deal with the different levels?

Thank you in advance for your feedback

 


2020_02_22_12_52_56_window.png

If I understand correctly, do you want to break down all the subassemblies?

Try this:

Option Explicit
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 vComp As Variant
Dim blnDone As Boolean
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swAssy = swModel
    blnDone = False
    While Not blnDone
        blnDone = True
        For Each vComp In swAssy.GetComponents(False)
            Set swComp = vComp
            Set swCompModel = swComp.GetModelDoc2
            If Not swCompModel Is Nothing Then
                If swCompModel.GetType = swDocASSEMBLY Then
                    swComp.Select4 False, Nothing, False
                    swAssy.DissolveSubAssembly
                    blnDone = False
                    Exit For
                End If
            End If
        Next
    Wend
End Sub

Find on: https://forum.solidworks.com/thread/61078

1 Like

Thank you, it's exactly what I was looking for.

Good night