The code below will return all Names of all BOMs in a drawing using the feature tree...Expand as needed
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature
While Not swFeat Is Nothing
If "BomFeat" = swFeat.GetTypeName Then
swFeat.Select2 True, 0
Set swFeat = swFeat.GetNextFeature
Thanks for the quick reply. What I'm actually looking for is a way to associate the name of each BOM with the name of the drawing sheet that contains it. However, there doesn't appear to be a property such as "swFeat.sheetname" that gives me this information. Any help is appreciated.
Thanks for your help; I have no idea how I missed that in all my searching. I haven't used it yet, but it looks like exactly what I need. I'll mark this correct for now in case I forget to check back once I use it.
For future reference, here is the code I ended up using. I cut this out of the main procedure and simplified it a bit, so the loops may not be what you want, but it should work with a bit of tweaking. Thanks to CADAdmin and Artem Taturevych for the help in getting this to work.
Sub Main() Dim swApp As Object Dim swModel As ModelDoc2 Dim swFeat As SldWorks.Feature Dim swBOMFeat As SldWorks.BomFeature Dim swBOMAnn As Variant Dim swBOMAnnParent As Variant Dim swBOMAnnitem As SldWorks.TableAnnotation Dim swAnn As SldWorks.Annotation Dim swViewTest As SldWorks.view Dim swSheetTest As SldWorks.Sheet 'Macro finds BOMS in drawing file and prints their names and the sheet name containing them to the immediate window Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc If swModel.GetType = swDocDRAWING Then 'Get array of BOMs' corresponding sheet names (this should be run in a loop that iterates through each sheet) Set swFeat = swModel.FirstFeature Do While Not swFeat Is Nothing If "BomFeat" = swFeat.GetTypeName Then Set swBOMFeat = swFeat.GetSpecificFeature2 swBOMAnn = swBOMFeat.GetTableAnnotations For Each swBOMAnnParent In swBOMAnn Set swBOMAnnitem = swBOMAnnParent Next swBOMAnnParent 'just use one of the returned items since they're all on the same sheet Set swAnn = swBOMAnnitem.GetAnnotation() If swAnn.OwnerType = swAnnotationOwner_e.swAnnotationOwner_DrawingSheet Then Set swSheetTest = swAnn.Owner ElseIf swAnn.OwnerType = swAnnotationOwner_e.swAnnotationOwner_DrawingView Then Set swViewTest = swAnn.Owner Set swSheetTest = swViewTest.Sheet End If Debug.Print (swSheetTest.GetName & " contains " & swBOMFeat.name) 'Prints sheet name containing BOM End If Set swFeat = swFeat.GetNextFeature Loop End If End Sub