AnsweredAssumed Answered

macro gets stuck, can't find out on which part

Question asked by K. V. on Dec 15, 2016
Latest reply on Dec 21, 2016 by K. V.

I can't figure out why this macro is stuck, anyone that can help me? It is for Deleting suppressed parts/assembly's

 

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

 

 

Set swApp = Application.SldWorks
End Sub

Outcomes