MACRO LIBRARY

Disable automatic cut list updating

Free public access. No account or subscription required.

Files

Disable automatic cut list updating

Code

Module: mMain

'Turns off automatic cutlist updating in all weldment parts in an assembly.
    
'Preconditions: Assembly is open
'Results: See immediate window.
    
'Notes:
'-If you want the changes to the part saved, un-comment the line
'   containing IModelDoc2::Save3.
'-This does not consider duplicates. A part will be processed as
'   many times as it exists in the assembly.
'-Technically, only sheet metal and weldment parts have cut lists,
'   but for simplicity this macro still traverses all parts.
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Sub main()
    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 vComps As Variant
    Dim i As Integer
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    
    If swModel Is Nothing Then Exit Sub
    If swModel.GetType <> swDocASSEMBLY Then Exit Sub
    
    Set swAssy = swModel
    
    vComps = swAssy.GetComponents(False)
    
    If IsEmpty(vComps) Then Exit Sub
    
    For i = 0 To UBound(vComps)
        Set swComp = vComps(i)
        Set swCompModel = swComp.GetModelDoc2
        
        If swCompModel Is Nothing Then
            Debug.Print "Couldn't process component (lightweight or suppressed): " & swComp.Name2
        Else
            Debug.Print "Processing component: " & swComp.Name2
            If swCompModel.GetType = swDocPART Then DisableAutomaticUpdates swCompModel
        End If
    Next i
End Sub
    
Private Sub DisableAutomaticUpdates(swModel As SldWorks.ModelDoc2)
    Dim swFeat As SldWorks.Feature
    Dim swBodyFolder As SldWorks.BodyFolder
    Set swFeat = swModel.FirstFeature
    Do While Not swFeat Is Nothing
        If swFeat.GetTypeName = "CutListFolder" Then
            Set swBodyFolder = swFeat.GetSpecificFeature2
            swBodyFolder.SetAutomaticUpdate False
            'swCompModel.Save3 swSaveAsOptions_Silent, Empty, Empty
            Exit Sub
        End If
        Set swFeat = swFeat.GetNextFeature
    Loop
End Sub