Hide Table of Contents

Get Components in Each BOM Table Row (VBA)

This example shows how to get the components in each row in a BOM table annotation.

'-------------------------------------------------

' Preconditions: Drawing document is open that contains

'                one or more bill of materials tables.

'

' Postconditions: None

'-------------------------------------------------

Option Explicit

 

Sub ProcessTableAnn(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, swTableAnn As SldWorks.TableAnnotation)

    Dim nNumRow As Long

    Dim J As Long

    Dim I As Long

    Debug.Print "   Table Title        " & swTableAnn.Title

    nNumRow = swTableAnn.RowCount

    Dim swBOMTableAnn As BomTableAnnotation

    Set swBOMTableAnn = swTableAnn

 

    For J = 0 To nNumRow - 1

        Debug.Print "   Row Number " & J & " Component Count  : " & swBOMTableAnn.GetComponentsCount(J)

        Dim vPtArr As Variant

        Dim swComp As Object

        Dim pt As Object

        vPtArr = swBOMTableAnn.GetComponents(J)

        If (Not IsEmpty(vPtArr)) Then

  

            For I = 0 To UBound(vPtArr)

                Set pt = vPtArr(I)

                Set swComp = pt

                If Not swComp Is Nothing Then

                    Debug.Print "           Component Name :" & swComp.Name2 & "      Configuration Name : " & swComp.ReferencedConfiguration

                Else

                    Debug.Print "  Could not get component."

                End If

            Next

        End If

            

    Next J

End Sub

 

Sub ProcessBomFeature(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, swBomFeat As SldWorks.BomFeature)

    Dim swFeat As SldWorks.Feature

    Dim vTableArr As Variant

    Dim vTable As Variant

    Dim swTable As SldWorks.TableAnnotation

    Set swFeat = swBomFeat.GetFeature

    vTableArr = swBomFeat.GetTableAnnotations

    For Each vTable In vTableArr

        Set swTable = vTable

        ProcessTableAnn swApp, swModel, swTable

    Next vTable

End Sub

 

Sub main()

    Dim swApp As SldWorks.SldWorks

    Dim swModel As SldWorks.ModelDoc2

    Dim swDraw As SldWorks.DrawingDoc

    Dim swSheet As SldWorks.Sheet

    Dim swFeat As SldWorks.Feature

    Dim swBomFeat As SldWorks.BomFeature

    Dim nNumSheet As Long

    Dim nRetval As Long

    Dim I As Long

    Dim bRet As Boolean

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swDraw = swModel

    Set swFeat = swModel.FirstFeature

    

    Do While Not swFeat Is Nothing

        If "BomFeat" = swFeat.GetTypeName Then

            Debug.Print "******************************"

            Debug.Print "Feature Name :- " & swFeat.Name

            Set swBomFeat = swFeat.GetSpecificFeature2

            ProcessBomFeature swApp, swModel, swBomFeat

        End If

        Set swFeat = swFeat.GetNextFeature

    Loop

End Sub



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Components in Each BOM Table Row (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2010 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.