Hide Table of Contents

Insert and Show BOM Table in Assembly Example (VB.NET)

This example shows how to insert and show a BOM table in an assembly document.

'------------------------------------------------
' Preconditions: 
' 1. Verify that the specified file and template exist.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Inserts an indented BOM table.
' 2. Inserts a split-circle stacked balloon, which uses the
'    BOM table item number for its upper text, 
'    at the selected face.
' 3. Examine the BOM table, stacked balloon, and Immediate
'    window.
'
' NOTE: Because this assembly document is used elsewhere,
' do not save changes.
'-------------------------------------------------
 
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
 
Partial Class SolidWorksMacro
 
    Sub Main()
 
        Dim swModel As ModelDoc2
        Dim swModelDocExt As ModelDocExtension
        Dim swBOMAnnotation As BomTableAnnotation
        Dim swBOMFeature As BomFeature
        Dim StackedBalloonParams As StackedBalloonOptions
        Dim swNote As Note
        Dim boolstatus As Boolean
        Dim BomType As Integer
        Dim nbrType as Integer
        Dim Configuration As String
        Dim TemplateName As String
        Dim nErrors As Integer
        Dim nWarnings As Integer
 
        ' Open assembly document
        swModel = swApp.OpenDoc6("C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\api\arm2.sldasm", swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", nErrors, nWarnings)
        swModelDocExt = swModel.Extension
 
 
        ' Insert BOM table
        TemplateName = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\lang\english\bom-standard.sldbomtbt"
        BomType = swBomType_e.swBomType_Indented
        Configuration = "Default"
        nbrType = swNumberingType_e.swNumberingType_Detailed
 
        swBOMAnnotation = swModelDocExt.InsertBomTable4(TemplateName, 0, 0, BomType, Configuration, False, nbrType, True, True)
        swBOMFeature = swBOMAnnotation.BomFeature
 
 
        ' Print the name of the configuration used for the BOM table
        Debug.Print("Name of configuration used for BOM table: " & swBOMFeature.Configuration)
 
 
        ' Insert BOM balloon for the selected face
        boolstatus = swModelDocExt.SelectByID2("""FACE", 0.091853347996107, -0.0104709589619745, 0.00174830255600256, False, 0, Nothing, 0)
 
        StackedBalloonParams =swModelDocExt.CreateStackedBalloonOptions()
        StackedBalloonParams.BalloonsPerLine = 10
        StackedBalloonParams.StackDirection = swStackedBalloonDirection_e.swStackedBalloonDir_Right
        StackedBalloonParams.Style = swBalloonStyle_e.swBS_SplitCirc
        StackedBalloonParams.LowerTextContent = swBalloonTextContent_e.swBalloonTextCustom
        StackedBalloonParams.LowerText = "Lower Text"
        StackedBalloonParams.ShowQuantity = True
        StackedBalloonParams.Size = swBalloonFit_e.swBF_Tightest
        StackedBalloonParams.QuantityPlacement = swBalloonQuantityPlacement_e.swBalloonQuantityPlacement_Top
        StackedBalloonParams.QuantityDenotationText = "Denotation Text"
        StackedBalloonParams.QuantityOverride = False
        StackedBalloonParams.ItemNumberStart = 1
        StackedBalloonParams.ItemNumberIncrement = 1
        StackedBalloonParams.ItemOrder = swBalloonItemNumbersOrder_e.swBalloonItemNumbers_DoNotChangeItemNumbers
 
        swNote = swModelDocExt.InsertStackedBalloon2(StackedBalloonParams)
 
        swModel.ViewZoomtofit2()
 
        ' Get whether balloon is a stacked balloon;
        ' if so, print the name of the balloon
        If swNote.IsStackedBalloon Then
 
            Debug.Print("Name of stacked balloon: " & swNote.GetName)
 
        End If
 
    End Sub
 
 
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    Public swApp As SldWorks
 
 
End Class


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:   Insert and Show BOM Table in Assembly Example (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) 2024 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.