SW 2014 API - Setting Lightweight to Resolved

Hello, I am having a lot of difficulty with this script.  The intention is to loop through all of the components in an assembly (which contains sub assemblies) and isolate all of the components that do not have material properties assigned to them (for weight estimation purposes).

I am getting an Error 91 at 'If swModel.MaterialIdName <> "" Then' for some components (but not all). Using the debugger, I can see that the suppression state of the component is not changed from lightweight to resolved by the .SetSuppression2 method.  Any idea why this would be?

The code is as follows.  Thank you!

Sub main()

Dim swModel As ModelDoc2

Dim vComps As Variant

Dim swcomp As SldWorks.Component2

Dim swAssy As SldWorks.AssemblyDoc

Dim i As Integer

Dim suppressionState As Long

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

If swModel.GetType = swDocASSEMBLY Then

    Set swAssy = swModel

    vComps = swAssy.GetComponents(False)

    For i = 0 To UBound(vComps)

       

        Debug.Print i & " / " & UBound(vComps)

       

        Set swcomp = vComps(i)

        suppressionState = swcomp.GetSuppression

       

        If suppressionState <> swComponentSuppressed Then

           

            If suppressionState <> swComponentFullyResolved Then

                swcomp.SetSuppression2 (swComponentFullyResolved)

            End If

            Set swModel = swcomp.GetModelDoc2

            If swModel.MaterialIdName <> "" Then

                swcomp.Visible = False

            End If

        End If

       

    Next i

End If

Set swModel = swApp.ActiveDoc

swModel.EditRebuild3

End Sub

SolidworksApi macros