Hide Table of Contents

Export BOM's Second Column to BOM Table Area Example (VBA)

This example shows how to export a BOM's second column to a BOM Table Area of a SOLIDWORKS MBD 3D PDF.

' Preconditions:
' 1. Verify that:
'    * specified assembly,
'    * specified SOLIDWORKS MBD 3D PDF theme, and
'    * c:\temp exist.
' 2. Open an Immediate window.
' Postconditions:
' 1. Inserts an indented BOM table in the assembly.
' 2. Gets the title of the second column in the BOM table
'    to export that column to the SOLIDWORKS MBD 3D PDF.
' 3. Gets the name of the BOM to map to the SOLIDWORKS
'    MBD 3D PDF.
' 4. Gets the SOLIDWORKS MBD 3D PDF data object.
'    a. Sets to display the SOLIDWORKS MBD 3D PDF after
'       publishing it.
'    b. Sets the path for the SOLIDWORKS MBD 3D PDF.
'    c. Sets the SOLIDWORKS MBD 3D PDF theme.
'    d. Sets the standard views for the SOLIDWORKS MBD 3D PDF.
'    e. Maps the BOM and exports its second column to a BOM
'       Table Area in the SOLIDWORKS MBD 3D PDF.
'    f. Publishes and displays the SOLIDWORKS MBD 3D PDF.
' 5. Examine c:\temp\MBDAssembly1.PDF and the Immediate window.
' NOTE: Because the assembly is used elsewhere, do not save changes.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swBOMAnnotation As SldWorks.BomTableAnnotation
Dim swTableAnnotation As SldWorks.TableAnnotation
Dim swBOMFeature As SldWorks.BomFeature
Dim swMBDPdfData As SldWorks.MBD3DPdfData
Dim fileName As String
Dim errors As Long
Dim warnings As Long
Dim bomType As Long
Dim tableTemplate As String
Dim columnNames(0) As String
Dim columns As Variant
Dim BOMTableName As String
Dim standardViews As Variant
Dim viewIDs(2) As Long
Dim nbrBOMTableAreas As Long
Sub main()
    Set swApp = Application.SldWorks
    fileName = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2017\tutorial\advdrawings\bladed shaft.sldasm"
    Set swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
    Set swModel = swApp.ActiveDoc
    Set swModelDocExt = swModel.Extension
    ' Insert indented BOM table in assembly
    bomType = swBomType_Indented
    tableTemplate = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\lang\english\bom-standard.sldbomtbt"
    Set swBOMAnnotation = swModelDocExt.InsertBomTable3(tableTemplate, 0, 1, bomType, "Default", False, swNumberingType_Detailed, True)        
    ' Get title of second column in BOM table to export to SOLIDWORKS MBD 3D PDF
    Set swTableAnnotation = swBOMAnnotation
    columnNames(0) = swTableAnnotation.GetColumnTitle(1)
    Debug.Print "Title of second column to export to SOLIDWORKS MBD 3D PDF: " & columnNames(0)
    columns = columnNames    
    ' Get name of BOM to map to SOLIDWORKS MBD 3D PDF
    Set swBOMFeature = swBOMAnnotation.BomFeature
    BOMTableName = swBOMFeature.Name
    Debug.Print "Name of BOM to map to SOLIDWORKS MBD 3D PDF: " & BOMTableName    
    ' Get MBD3PdfData object
    Set swMBDPdfData = swModelDocExt.GetMBD3DPdfData    
    ' Set to display SOLIDWORKS MBD 3D PDF
    swMBDPdfData.ViewPdfAfterSaving = True      
    ' Set path for SOLIDWORKS MBD 3D PDF
    swMBDPdfData.FilePath = "c:\temp\MBDAssembly1.PDF"     
    ' Set SOLIDWORKS MBD 3D PDF theme
    swMBDPdfData.ThemeName = "c:\program files\solidworks corp\solidworks\data\themes\simple assembly (a4, landscape)\theme.xml"    
    ' Set standard views for SOLIDWORKS MBD 3D PDF
    viewIDs(0) = swStandardViews_e.swFrontView
    viewIDs(1) = swStandardViews_e.swTopView
    viewIDs(2) = swStandardViews_e.swDimetricView
    standardViews = viewIDs
    swMBDPdfData.SetStandardViews (standardViews)    
    ' Map BOM and export its second column to a BOM Table Area 
    nbrBOMTableAreas = swMBDPdfData.GetBomAreaCount
    If nbrBOMTableAreas > 0 Then
        swMBDPdfData.SetBomTable 0, BOMTableName, columns
    End If
    swModelDocExt.PublishTo3DPDF swMBDPdfData
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

Subject:   Feedback on Help Topics
Page:   Export BOM's Second Column to BOM Table Area Example (VBA)
*   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:


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

Web Help Content Version: API Help (English only) 2017 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.