Hide Table of Contents

Get BOM Tables (VB.NET)

This example shows how to get the BOM tables in a drawing document. This example also shows how to get each BOM table's name, display status, whether components with multiple configurations appear as one item in the BOM table, and the part configuration grouping setting.

'------------------------------------------------------------------
' Preconditions:
' 1. Read the SolidWorks Document Manager API Help "Getting Started"
'    topic and register the required DLLs.
' 2. Load the latest SolidWorks.Interop.swdocumentmgr.dll
'    interop assembly by:
'    a. Right-clicking the project name in the Project Explorer.
'    b. Clicking Add Reference.
'    c. Selecting the interop assembly on the .NET
'       tab or browsing for the DLL in install_dir/api/redist/CLR2.
' 3. Substitute your license key for "your_license_key" in the code.
' 4. Make sure that the drawing document opened by this application
'    exists.
' 5. Open the Immediate window.
'
' Postconditions: Printed to the Immediate window:
' * Document's path and file name
' * Date the document was last saved
' * Name of the BOM table
' * Whether the BOM table is hidden
' * Whether the BOM table contains components with multiple configurations,
'   and whether to display the configurations as one item
' * Part configuration grouping setting
'
' NOTE: This sample application was developed using
' Microsoft Visual Studio 2008. If you use another version of
' Microsoft Visual Studio, you might need to add more references to get
' this application to compile.
'------------------------------------------------------------------

Imports SolidWorks.Interop.swdocumentmgr
Imports System
Imports System.Diagnostics

Module Module1

    
Dim dmClassFact As SwDMClassFactory
    
Dim dmDocMgr As SwDMApplication3
    
Dim dmDoc As SwDMDocument15
    
Dim dmTable As ISwDMTable4
    
Dim dmError As SwDmDocumentOpenError
    
Dim nameDrawing As String

    Sub Main()

        dmClassFact = CreateObject(
"SwDocumentMgr.SwDMClassFactory")
        dmDocMgr = dmClassFact.GetApplication(
"your_license_key") 'Do not distribute
        nameDrawing = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\introsw\cabinet_bath.slddrw"

        'Get the SolidWorks drawing document
        dmDoc = dmDocMgr.GetDocument(nameDrawing, SwDmDocumentType.swDmDocumentDrawing, False, dmError)
        
'Debug.Print("Document's last saved date: " & dmDoc.LastSavedDate)
        Debug.Print("Document's full name: " & dmDoc.FullName)
        Debug.Print(
"Date document last saved: " & dmDoc.LastSavedDate)

        
' Get the names of the BOM tables in the SolidWorks drawing document
        Dim tableNames As Object
        tableNames = dmDoc.GetTableNames(SwDmTableType.swDmTableTypeBOM)
        
Dim i As Integer
        If Not IsNothing(tableNames) Then
            For i = 0 To UBound(tableNames)
                dmTable = dmDoc.GetTable(tableNames(i))
                
' Get the BOM table names
                ' Determine whether:
                ' * BOM table is hidden
                ' * Configurations appear with same
                '   item number if BOM table contains components
                '   with multiple configurations
                ' Get the component configuration grouping
                Debug.Print(" BOM table name: " & dmTable.Name)
                Debug.Print(
"   Is BOM table hidden? " & dmTable.Hidden)
                Debug.Print(
"   If BOM table contains components with multiple configurations, display as one item? " & dmTable.DisplayAsOneItem)
                Debug.Print(
"   Part configuration grouping? " & dmTable.PartConfigurationGrouping)
            
Next
        End If
    End Sub
End
Module



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 BOM Tables (VB.NET)
*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) 2013 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.