MACRO LIBRARY

Get weldment bodies

Free public access. No account or subscription required.

Files

Get weldment bodies

Code

Module: mMain

'Demonstrates how to get weldment bodies
    
'Preconditions: part is open.
'Results: see immediate window.
    
'Notes:
'The cutlist folder must be updated before this macro can print any weldment _
    body names. This update is done automatically in the macro.
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swBody As SldWorks.Body2
Dim swBodyFolder As SldWorks.BodyFolder
Dim swFeat As SldWorks.Feature
Dim vBodies As Variant
Dim i As Integer
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swPart = swModel
    
    If swPart.IsWeldment = False Then Exit Sub
    
    Set swFeat = swModel.FirstFeature
    Do While Not swFeat Is Nothing
        If swFeat.GetTypeName = "SolidBodyFolder" Then
            Set swBodyFolder = swFeat.GetSpecificFeature2
            swBodyFolder.UpdateCutList
        End If
        If swFeat.GetTypeName = "CutListFolder" Then
            Set swBodyFolder = swFeat.GetSpecificFeature2
            swBodyFolder.UpdateCutList
            vBodies = swBodyFolder.GetBodies
            If IsEmpty(vBodies) = False Then
                For i = 0 To UBound(vBodies)
                    Set swBody = vBodies(i)
                    Debug.Print swBody.Name
                Next i
            End If
        End If
        Set swFeat = swFeat.GetNextFeature
    Loop
End Sub