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