MACRO LIBRARY

Get BOM table on specific drawing sheet

Free public access. No account or subscription required.

Files

Get BOM table on specific drawing sheet

Code

Module:

'Demonstrates how to get a BOM table on a specific drawing sheet.
    
'Precondition: Drawing is open.
'Result: See immediate window.
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Const SHEET_NAME As String = "Sheet1"
    
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As ModelDoc2
    Dim swDraw As DrawingDoc
    Dim swView As View
    Dim swTableAnn As TableAnnotation
    Dim swBomTableAnn As BomTableAnnotation
    Dim vTableAnns As Variant
    Dim i As Integer
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    swDraw.ActivateSheet SHEET_NAME
    Set swView = swDraw.GetFirstView
    vTableAnns = swView.GetTableAnnotations
    
    If IsEmpty(vTableAnns) Then Exit Sub
    
    For i = 0 To UBound(vTableAnns)
        Set swTableAnn = vTableAnns(i)
        If swTableAnn.Type = swTableAnnotationType_e.swTableAnnotation_BillOfMaterials Then
            Set swBomTableAnn = swTableAnn
            
            Debug.Print "Bom table found"
            Exit Sub
        End If
    Next i
    
    Debug.Print "No BOM table found"
End Sub