AnsweredAssumed Answered

Insert BOM with template

Question asked by Sussi Birkevang on Sep 1, 2020
Latest reply on Sep 1, 2020 by Sussi Birkevang

Hi

 

I have found a macro in this forum, and modified it for my needs. 

First Macro - Insert BOM API 

Yesterday it worked fine, and I published it for my colleagues - to day it will not work. When I did some research, it turns out that Solidworks API help, have an example with this macro, so I checked the code up against it and they pretty much look the same, and they give the same error.

2020 SOLIDWORKS API Help - Insert BOM Table Example (VBA)  

 

The error: 

Set swBomFeat = swBomAnn.bomfeature
Error message: swBomAnn.bomfeature = <Objekt variable or with block variable not set>

My API-abilities are enough to modify others work, but not to write from scratch.

I can therefore not figure out what the problem is. Can anyone help me?

 

Best regards

Sussi

 

My version:

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeatMgr As SldWorks.featuremanager
Dim swView As SldWorks.View
Dim swBomAnn As bomtableannotation
Dim swBomFeat As SldWorks.bomfeature
Dim anchorType As Long
Dim bomType As Long
Dim configuration As String
Dim bomTemplate As String
Dim Names As Variant
Dim visible As Variant
Dim boolStatus As Boolean
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim vfeature As Variant
Dim swCustProp As SldWorks.CustomPropertyManager
Dim val(1) As String
Dim valout(1) As String
Const BomFeatureName As String = "Bill of Materials"
Dim swannotationtable As TableAnnotation
Dim result As Boolean
Dim featuremanager As featuremanager
Dim feature As feature
Dim vfeatures As Variant
Dim i As Long
Dim bomfeature As bomfeature
Dim bomtableannotation As bomtableannotation
Dim rowletter As String

Sub Main()


Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeatMgr = swModel.featuremanager
Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheet

 

'Select View
swModel.ClearSelection2 True
Set swView = swDraw.GetCurrentSheet.GetViews()(0)

'Insert BOM Table
bomTemplate = "C:\ODIN\Templates\SW\Templates\BOM\Drawing_PartlistODIN.sldbomtbt"

anchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_BottomRight

bomType = SwConst.swBomType_e.swBomType_PartsOnly

configuration = "Default"

Set swBomAnn = swView.InsertBomTable4(True, 5, 5, anchorType, bomType, configuration, bomTemplate, False, swNumberingType_e.swNumberingType_Flat, True)
Set swBomFeat = swBomAnn.bomfeature
Names = swBomFeat.GetConfigurations(False, visible)
visible(0) = True
boolStatus = swBomFeat.SetConfigurations(True, visible, Names)
swFeatMgr.UpdateFeatureTree


End Sub

Outcomes