Hello everyone,
I am working on a SolidWorks VBA macro that iterates through a drawing's Bill of Materials (BOM) to verify components and open their respective files. I have encountered a critical mismatch between the visual BOM and the API output.
BOM Settings:
Type: Parts Only
Sorting: Sorted by
PART NUMBER(NOT following assembly order).
The Problem:
Row Count Mismatch: The physical BOM table in the drawing visually contains 68 data rows. However,
swTableDoc.TotalRowCountreturns 72 rows (likely counting headers/footers or hidden split rows).Skipped Items: Because the table is sorted by Part Number, the Item Numbers in Column 0 are out of order. My macro uses a continuous integer loop (
For iInput = 1 To TotalRowCount - 1) and scans Column 0 usingswTableDoc.Text(iSearchRow, 0)to map the correct row index. During this process, the macro completely skips 2 specific top-level parts that are clearly visible on the screen.
How I access the data in my code (as shown in attached screenshots):
I acquire the table via:
Set swBomTable = swBomFeat.GetTableAnnotations()(0)I scan for the target row index based on the text:
If Trim(swTableDoc.Text(iSearchRow, 0)) = CStr(iInput)Then I retrieve the components via:
vComps = swBomTable.GetComponents2(targetIndexFromScan, 0)
What is causing this discrepancy? Is there a known issue where sorting a "Parts Only" BOM causes GetComponents2 or the row index mapping to shift or fail to read specific top-level components?
I would appreciate any advice on how to handle index mapping correctly under these specific BOM conditions.
Thank you!
