Files
Insert top-level only BOM
Code
'Demonstrates how to insert a BOM with BOM type "Top level only"
'Preconditions: drawing view is selected
'Result: top-level only BOM is inserted at 0, 0
'Note: If you want the BOM inserted at another location then you will need
' to do one of the following with IView::InsertBomTable3.
' 1. Specify that coordinate in the X and Y coordinates
' 2. Specify that you want to use the anchor point. To set the anchor
' point programmatically, use ITableAnchor::Position. Note that this
' still requires numerical input.
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Dim swBomTableAnn As SldWorks.BomTableAnnotation
Dim swBomFeat As SldWorks.BomFeature
Dim vConfigNames As Variant
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swView = swSelMgr.GetSelectedObject6(1, -1)
Set swBomTableAnn = swView.InsertBomTable3(False, 0, 0, _
swBOMConfigurationAnchor_TopRight, _
swBomType_TopLevelOnly, Empty, Empty, False)
Set swBomFeat = swBomTableAnn.BomFeature
'As stated in the remarks for IView::InsertBomTable3 and InsertBomTable4, _
IBomFeature::GetConfigurations and SetConfigurations must be used to _
add the configs. Commenting the next two lines will result in a BOM table _
with only a header row.
vConfigNames = swBomFeat.GetConfigurations(False, Empty)
swBomFeat.SetConfigurations True, Empty, vConfigNames
swModel.EditRebuild3
End Sub