perhaps someone can help me with my macros?
We used to put on our drawings the excel-based BOM.
From now on we want to delete the excel-based BOM and use the SW BOM.
I wrote a macro to delete all the excel-based BOMs in the drawing.
Another macro puts the SW BOM on the drawing.
The SW BOM is placed correctly on the drawing but:
The SW BOM is not shown in the feature tree!
I tryed to place the SW BOM manually on the drawing, but with the same result.
There must be something wrong in the macro "Delete excel-based BOM" but I can't figure out what.
Manualy deleting the excel-based BOM and inserting the SW BOM via macro works fine.
Technically both macros are working. Only the feature tree does not update.
If I type something in the filterfield above the feature tree and remove the entry from filterfield, suddenly the BOM ist displayed.
Perhaps anyone has come across the same problem an can help me.
VBA macro "Delete excel-based BOM":
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeatMgr As SldWorks.FeatureManager
Dim swFeat As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Dim swSubSubFeat As SldWorks.Feature
Dim swView As SldWorks.View
Dim oViewBOMObj As BomTable
Dim swViewBomTable As SldWorks.BomTable
Dim swdraw As SldWorks.DrawingDoc
Dim bRet As Boolean
Dim SheetNames As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeatMgr = swModel.FeatureManager
Set swdraw = swModel
SheetNames = swdraw.GetSheetNames
swFeatMgr.EnableFeatureTree = False
Debug.Print "File = " & swModel.GetPathName
Set swFeat = swModel.FirstFeature
Do While Not swFeat Is Nothing
If swFeat.GetTypeName = "DrSheet" Then
Debug.Print " " & swFeat.Name & " [" & swFeat.GetTypeName & "]"
Set swSubFeat = swFeat.GetFirstSubFeature
Do While Not swSubFeat Is Nothing
Debug.Print " " & swSubFeat.Name & " [" & swSubFeat.GetTypeName & "]"
Set swSubSubFeat = swSubFeat.GetFirstSubFeature
Do While Not swSubSubFeat Is Nothing And InStr(swSubFeat.GetTypeName, "View") > 0
If swSubSubFeat.GetTypeName = "BomFeature" Then
Debug.Print " " & swSubSubFeat.Name & " [" & swSubSubFeat.GetTypeName & "]" & " [" & swSubSubFeat.GetID & "]"
Set swView = swdraw.FeatureByName(swSubFeat.Name).GetSpecificFeature()
Set oViewBOMObj = swView.GetBomTable
Set swViewBomTable = oViewBOMObj
Set swSubSubFeat = swSubSubFeat.GetNextSubFeature
If Not oViewBOMObj Is Nothing Then
bRet = swViewBomTable.Select(False, 0)
bRet = swModel.DeleteSelection(False)
Set oViewBOMObj = Nothing
Set swSubFeat = swSubFeat.GetNextSubFeature
Set swFeat = swFeat.GetNextFeature
Set swModel = Nothing
I think there is an problem with looping through the features.
Because when I run the macro without any deleting, the feature tree is "frozen" and a new SW BOM will not be shown.
If I expand the view with the excelbased BOM and run the "Delete excel-based BOM" macro, the excel-based BOM is still present.
When I try to select the excel-based BOM, SW crashes.
Typing something in the filterfield forces the recalculating of the featuretree and the excel-based BOM entry has vanished.
After running the macro "Insert BOM":
Any help is much apprechiated.
Thank you, have nice a christmas, a happy new year and stay healthy!