MACRO LIBRARY

Suppress all folders in model with specified name

Free public access. No account or subscription required.

Files

Suppress all folders in model with specified name

Code

Module: mMain

'Demonstrates how to suppress folders in a model.
    
'Preconditions: Part or assembly is open.
'Result: All folders with the name FOLDER_NAME are suppressed.
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Option Compare Text
    
Const FOLDER_NAME As String = "Fasteners"
    
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    
    TraverseModel swModel, swModel, 1
End Sub
    
Private Sub TraverseModel(swModel As SldWorks.ModelDoc2, model As Object, nLevel As Integer)
    Dim swFeat As SldWorks.Feature
    Dim swComp As SldWorks.Component2
    Dim strPad As String
    
    Set swFeat = model.FirstFeature
    
    Do While Not swFeat Is Nothing
        If swFeat.Name = FOLDER_NAME And _
            swFeat.GetTypeName = "FtrFolder" And _
            InStr(1, swFeat.Name, "___EndTag___", vbTextCompare) = 0 Then
            
            swFeat.Select2 False, Empty
            swModel.EditSuppress2
            
        End If
        
        If swFeat.GetTypeName = "Reference" Then
            Set swComp = swFeat.GetSpecificFeature2
            TraverseModel swModel, swComp, nLevel + 1
        End If
        
        Set swFeat = swFeat.GetNextFeature
    Loop
End Sub