Delete Suppressed Components from an Assembly

I am looking for a way to delete suppressed components from an assembly. I searched through the api forums and found some code to do this, but i am pretty sure it is in German. I cannot read German, so I am having to look elsewhere. Any input on this would be appreciated.

SolidworksApi macros
Answers 2
DG
DG 2011-12-07 Best Answer

You may want to check the macro shared here and modify it per your need:  https://forum.solidworks.com/message/193791#193791

The idea if to traverse thru assembly, find and delete suppressed parts.

SF
SF 2011-12-07

I actually got the code below to work. It was the code i stated i previously found. The only bad thing is if you have multiple Configs using the same parts you are in trouble. I ended up just writing a chunk of code in another program that deletes out the configs that I wasnt using. I believe it was along the same lines of the TraverseComponent method you gave me the link to.

Option Explicit
Dim swApp As SldWorks.SldWorks
Public iCountDelete As Integer
Public sNameDelete As String

Sub main()

    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
   
    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc
    Set swConf = swModel.GetActiveConfiguration
    Set swRootComp = swConf.GetRootComponent

    TraverseComponent swRootComp, swModel, 0
   
End Sub

Sub TraverseComponent(swComp As SldWorks.Component2, RootModel As SldWorks.ModelDoc2, ByVal iLev As Integer)

    Dim vChildComp            As Variant
    Dim swChildComp           As SldWorks.Component2
    Dim swCompConfig          As SldWorks.Configuration
    Dim i                     As Long
    Dim iRueck                As Double
    Dim oModel, oModComp      As ModelDoc2
    Dim iSel                  As Object
    Dim b                     As Boolean
    Dim o                     As Object
    Dim iLevel                As Integer
  
    iLevel = iLev + 1   ' This variable is meant to show the sub-level the macro currently works in
    Debug.Print iLevel & "|" & swComp.Name

    vChildComp = swComp.GetChildren
  
    For i = 0 To UBound(vChildComp)
        Set swChildComp = vChildComp(i)
       
        If swChildComp.IsSuppressed Then   ' Identified a suppressed part - Aim is to kill this one, no matter if it is assembly or part
            Debug.Print "Suppr.: " & swChildComp.Name
            swComp.Select4 False, Nothing, False
            RootModel.EditAssembly
            b = swChildComp.Select4(False, iSel, False)
            b = RootModel.Extension.DeleteSelection2(1)
            iCountDelete = iCountDelete + 1
            RootModel.ClearSelection2 (True)
            RootModel.EditAssembly

            If b = False Then i = swChildComp.SetSuppression2(0)
         End If

        TraverseComponent swChildComp, RootModel, iLevel
    Next i

End Sub