Checking for BOM, and deleting the old one(s)

Hi all,

I use this code to check if the sheet contains a BOM

        Set swView = swDraw.GetFirstView

        Set swTableAnn = swView.GetFirstTableAnnotation

        On Error GoTo Label1

        If swTableAnn.Type = swTableAnnotation_BillOfMaterials Then

        Debug.Print "There is a BOM"

        swBom = 1

        Else

Label1:

        Debug.Print "NO BOM"

        swBom = 0

        End If

       

But if there is no BOM,

If swTableAnn.Type = swTableAnnotation_BillOfMaterials Then

gives an error. (object variable or with block variable not set)

I tried to circumvent it with an 'on error goto label1' code... but that doesn't work when a drawing has more than 1 sheet.

***

I use this code to delete all BOMs, but I need it to do it only for the active sheet. (else it will also delete a bom on sheet 2 and then the code above thinks that that sheet never had a bom). It does need to delete all BOMs per sheet though because sometimes the engineers have multiple BOM's on a single sheet.

        While Not swFeat Is Nothing

        If "BomFeat" = swFeat.GetTypeName Then

        swFeat.Select2 True, -1

        End If

        Set swFeat = swFeat.GetNextFeature

        Wend

        swModel.Extension.DeleteSelection2 swDeleteSelectionOptions_e.swDelete_Absorbed

SolidworksApi macros