Hide Table of Contents

Get BOM Balloon Properties Example (VBA)

This example shows how to get the properties of a BOM balloon.

'----------------------------------------------------------
' Preconditions:
' 1. Verify that the specified assembly document to open
'    exists.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Opens the specified assembly document.
' 2. Inserts a BOM table.
' 3. Inserts a BOM balloon.
' 4. Gets and sets the BOM balloon's properties.
' 5. Examine the Immediate window.
'
' NOTE: Because this 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 swSelectionMgr As SldWorks.SelectionMgr
Dim swNote As SldWorks.Note
Dim swAnnotation As SldWorks.Annotation
Dim attachedEntityArray As Variant
Dim attachedEntityTypeArray As Variant
Dim swEntity As SldWorks.Entity
Dim swComponent As SldWorks.Component2
Dim swComponentModel As SldWorks.ModelDoc2
Dim swBomTableAnnotation As SldWorks.BomTableAnnotation
Dim swBomBalloonParams As SldWorks.BalloonOptions
Dim i As Long
Dim fileName As String
Dim status As Boolean
Dim errors As Long
Dim warnings As Long
Sub main()
    Set swApp = Application.SldWorks    
    'Open assembly, create BOM table, and select BOM balloon
    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 swModelDocExt = swModel.Extension
    Set swBomTableAnnotation = swModelDocExt.InsertBomTable3("C:\Program Files\SolidWorks Corp\SolidWorks\lang\english\bom-standard.sldbomtbt", 618, 568, swBomType_e.swBomType_TopLevelOnly, "", False, swNumberingType_e.swNumberingType_None, False)
    status = swModelDocExt.SelectByID2("", "FACE", 1.39294427590926E-02, 0.059464184169542, 8.2768338148469E-03, False, 0, Nothing, 0)
    Set swBomBalloonParams = swModelDocExt.CreateBalloonOptions()
    swBomBalloonParams.Style = swBalloonStyle_e.swBS_SplitCirc
    swBomBalloonParams.Size = swBalloonFit_e.swBF_Tightest
    Set swNote = swModelDocExt.InsertBOMBalloon2(swBomBalloonParams)
    status = swModelDocExt.SelectByID2("DetailItem2@Annotations", "NOTE", 4.31152692774954E-03, 6.99703491909496E-02, 3.3561420724473E-03, False, 0, Nothing, 0)
    'Get and set BOM balloon properties
    Set swSelectionMgr = swModel.SelectionManager
    Set swNote = swSelectionMgr.GetSelectedObject6(1, -1)
    Set swAnnotation = swNote.GetAnnotation
    attachedEntityArray = swAnnotation.GetAttachedEntities2
    attachedEntityTypeArray = swAnnotation.GetAttachedEntityTypes
    Debug.Print "File = " & swModel.GetPathName
    Debug.Print "  Name = " & swAnnotation.GetName
    swNote.SetBomBalloonText swDetailingNoteTextContent_e.swDetailingNoteTextCustom, "ABC", swDetailingNoteTextContent_e.swDetailingNoteTextCustom, "EFG"
    Debug.Print "    Upper text  = " & swNote.GetBomBalloonText(True) & " [" & swNote.GetBomBalloonTextStyle(True) & "]"
    Debug.Print "    Lower text  = " & swNote.GetBomBalloonText(False) & " [" & swNote.GetBomBalloonTextStyle(False) & "]"
    Debug.Print "    Balloon fit = " & swNote.GetBalloonSize
    Debug.Print "    Balloon style = " & swNote.GetBalloonStyle
    Debug.Print "    Is stacked? " & swNote.IsStackedBalloon
    Debug.Print "    Is stacked master? " & swNote.IsStackedBalloonMaster
    For i = 0 To UBound(attachedEntityArray)
        Debug.Print "    Attached entity type = " & attachedEntityTypeArray(i)
        If swSelNOTHING <> attachedEntityTypeArray(i) Then
            Set swEntity = attachedEntityArray(i)
            Set swComponent = swEntity.GetComponent
            Set swComponentModel = swComponent.GetModelDoc
            Debug.Print "    Attached entity = " & swComponent.GetPathName & " <" & swComponent.ReferencedConfiguration & ">" & " --> " & swComponentModel.GetPathName
        End If
    Next i    
    swModel.ViewZoomtofit2

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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get BOM Balloon Properties Example (VBA)
*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) 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.