AnsweredAssumed Answered

Macro to extract information from BOM (using GetComponents) skips some items for no reason!

Question asked by Tyler Hilgendorf on Oct 13, 2017
Latest reply on Oct 18, 2017 by Elmar Klammer

I have a macro which opens up drawings, and if they have a BOM, extracts information about those parts from the BOM. For some reason, that macro is skipping some lines of the BOM. The relevant portion of code is here:


Sub BOMContents(bcBOMfeat As SldWorks.BomFeature)


Dim bcV As Variant

Dim bcBTA As SldWorks.BomTableAnnotation

Dim bcTA As SldWorks.TableAnnotation


bcV = bcBOMfeat.GetTableAnnotations

Set bcBTA = bcV(0)

Set bcTA = bcBTA


Dim i As Long

For i = 0 To bcTA.RowCount - 1

    'Get component objects for BOM line item

    Dim vComp As Variant

    vComp = bcBTA.GetComponents(i)



I've watched the macro execute line-by-line, and the line highlighted in red is the problem. Very rarely, for some lines, GetComponents returns nothing and vComp remains empty! This doesn't happen randomly, it always happens on the same line of the same BOM. If I re-order the BOM so that the part that fails is on a new row, the error "follows" that part.


Another thing: the part that is failing is actually just one configuration of a part. Other configurations of the same part in the same BOM work just fine. I have even tried creating a completely new configuration of the part, updating the assembly to only reference that new configuration, and completely deleted the old "bad" configuration. The error still happens, now to that new configuration.


Any idea what might be causing this? I spent a whole day making all sorts of changes to the part configurations to try to track down what might be causing the error, with no luck. Nothing I did could reproduce the error on other configurations, and nothing I did could eliminate the error on the "bad" configuration.


Another only tangentially-related question: what does GetComponents actually extract from the BOM? I see that, when it does work, it returns an array. However, that array is always of different lengths that seem to have nothing to do with the information that is actually in the BOM!