2 Replies Latest reply on Nov 19, 2015 12:36 PM by Michael Reilly

    SW 2014 API - Setting Lightweight to Resolved

    Michael Reilly

      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




      End Sub

        • Re: SW 2014 API - Setting Lightweight to Resolved
          Amen Allah Jlili

          You're not calling the enum properly. Replace swComponentFullyResolved with swComponentSuppressionState_e.swComponentFullyResolved
          or just replace
          swComponentFullyResolved its value 2.



          If you want to use swComponentSuppressionState_e make sure that solidworks const library tlb is referenced. VBA automatically references it for you when you're create a new macro.


          Public Enum swComponentSuppressionState_e
              swComponentSuppressed = 0
              swComponentLightweight = 1
              swComponentFullyResolved = 2