Hide Table of Contents

Get BOM Tables (C#)

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
//
// 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.
//------------------------------------------------------------------

using SolidWorks.Interop.swdocumentmgr;
using System;
using System.Diagnostics;

namespace swDMTableCSharp
{
    
class Module1
    {
        
static void Main()
        {
            
SwDMClassFactory dmClassFact = default(SwDMClassFactory);
            
SwDMApplication3 dmDocMgr = default(SwDMApplication3);
            
SwDMDocument15 dmDoc = default(SwDMDocument15);
            
ISwDMTable4 dmTable = default(SwDMTable4);
            
SwDmDocumentOpenError dmError = default(SwDmDocumentOpenError);
            
string nameDrawing = "";

            dmClassFact =
new SwDMClassFactory();
            dmDocMgr = (
SwDMApplication3)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 = (SwDMDocument15)dmDocMgr.GetDocument(nameDrawing, SwDmDocumentType.swDmDocumentDrawing, false, out 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
            string[] tableNames = null;
            tableNames = (
string[])dmDoc.GetTableNames(SwDmTableType.swDmTableTypeBOM);
            
int i = 0;
            
if ((tableNames != null))
            {
                
for (i = 0; i <= tableNames.Length-1; i++)
                {
                    dmTable = (
SwDMTable4)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, and
                    // 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);
                }
            }
        }
    }
}



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 (C#)
*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.