AnsweredAssumed Answered

MACRO NOT WORKING IN SOLIDWORKS 2019 through driveworks

Question asked by Kaijiun Cheang on May 14, 2019
Latest reply on May 21, 2019 by Kaijiun Cheang


I got a macro that works before. This macro is used to add an BOM into drawing. When i run it through driveworks, it is not working. It shows (A serious error occurred on open macro file. The system could be in an unstable state now.).

But i have no problem run it with drawing opened.


Then i recalled it could be the newly updated solidworks 2019 that i am running not long ago. But i don't have any knowledge to update the command to the latest library. Can anyone tell which one has been obselete? Or any problem that i am not aware of?





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 tableTemplate As String
Dim Names As Variant
Dim visible As Variant
Dim boolStatus As Boolean
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet


Sub Main()


Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeatMgr = swModel.FeatureManager
Set swDraw = swModel


swModel.ActivateSheet "Sheet1"

'Select View

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

'Insert BOM Table

anchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight
bomType = SwConst.swBomType_e.swBomType_TopLevelOnly

swModel.ClearSelection2 True

configuration = "CLOSED-OFFSET BIFOLD" '"Default"
tableTemplate = "P:\Data\Engineering\SOLIDWORKS\TEMPLATE\AM BOM TABLE.sldbomtbt" '"C:\KMI-Vault\Admin Files\SW - Templates\TABLES\kTable.sldbomtbt"

boolStatus = swModel.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swOneConfigOnlyTopLevelBom, 0, True)

Set swBomAnn = swView.InsertBomTable4(True, 0, 0, anchorType, bomType, configuration, tableTemplate, False, 2, False)
Set swBomFeat = swBomAnn.BomFeature
Names = swBomFeat.GetConfigurations(False, visible)
visible(0) = True
boolStatus = swBomFeat.SetConfigurations(True, visible, Names)


End Sub