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 :
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
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?
Set swSubSubFeat = swSubSubFeat.GetNextSubFeature
Set swSubFeat = swSubFeat.GetNextSubFeature
Set swFeat = swFeat.GetNextFeature
swFeatMgr.EnableFeatureTree = True
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.