Hi Guys,
we used to put an excel based BOM on our SW Drawings.
In the future we would like to use the SW BOM.
And now we have the challenge, that we need to replace the excelbased BOM with the SW BOM.
I would like to provide my collegs a macro for fast BOM replace.
Unfortunatly I can't use the "GetTableAnnotations" to select the BOM Feature in the FeatureTree.
So I loop through the Tree and try to select the BOM.
Through the loop I can list all FeatureNames and the BOM is also listet.
But I'm stuck when it comes to selecting the BOM.
Trying "SelectByID2" is always "false".
My first Macro attempt :
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeatMgr As SldWorks.FeatureManager
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swFeat1 As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Dim swSubSubFeat As SldWorks.Feature
Dim swSubSubSubFeat As SldWorks.Feature
Dim swModExt As SldWorks.ModelDocExtension
Dim i As Long
Dim bRet As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeatMgr = swModel.FeatureManager
Set swSelMgr = swModel.SelectionManager
Set swModExt = swModel.Extension
swFeatMgr.EnableFeatureTree = False
swModel.ClearSelection2 True
Debug.Print "File = " & swModel.GetPathName
Set swFeat = swModel.FirstFeature
Do While Not swFeat Is Nothing
bRet = swFeat.Select2(True, 0)
Debug.Print " " & swFeat.Name & " [" & swFeat.GetTypeName & "]"
Set swSubFeat = swFeat.GetFirstSubFeature
Do While Not swSubFeat Is Nothing
bRet = swSubFeat.Select2(True, 0)
Debug.Print " " & swSubFeat.Name & " [" & swSubFeat.GetTypeName & "]"
Set swSubSubFeat = swSubFeat.GetFirstSubFeature
Do While Not swSubSubFeat Is Nothing And InStr(swSubFeat.GetTypeName, "View") > 0
bRet = swSubSubFeat.Select2(True, 0)
If swSubSubFeat.GetTypeName = "BomFeature" Then
Debug.Print " " & swSubSubFeat.Name & " [" & swSubSubFeat.GetTypeName & "]" & " [" & swSubSubFeat.GetID & "]"
'-----
'Here I want to delete the selected Feature.
'Why is the "swSubSubFeat.Select2(True,0)" false?
'------
End If
Set swSubSubFeat = swSubSubFeat.GetNextSubFeature
Loop
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
Set swFeat = swFeat.GetNextFeature
Loop
swFeatMgr.EnableFeatureTree = True
End Sub
Perhaps there is something with the Featuremanager what I don't understand.
I have to mention that I'm not pro in SW Macro programing.
Any help is much appreciated.
Many Thanks in advance.
SolidworksApi/macros