1 Reply Latest reply on Sep 13, 2015 5:10 PM by Josh Brady

    Parts not getting extracted in order

    Arvind Purushotaman

      Hello,

       

      I have wrote a small snippet that extracts the components in the assembly and check if that is an assembly or part by itself and prints all the part names. The command GetComponents gets the components and stores it in an array alphabetically.

       

      Can someone explain me how to extract the parts from the feature tree in the exact order?

       

      My code is as follows:

       

      Dim swApp                            As SldWorks.SldWorks

      Dim swAssem                       As SldWorks.AssemblyDoc

      Dim ComponentArray          As Variant

      Dim Component                   As SldWorks.Component2

      Dim swCompModel              As SldWorks.ModelDoc2

      Dim swsubAssy                    As SldWorks.AssemblyDoc

      Dim subAssyCompArray     As Variant

      Dim SubAssyComp              As SldWorks.Component2

       

      Sub main()

       

      Set swApp = Application.SldWorks

      Set swAssem = swApp.ActiveDoc

      ComponentArray = swAssem.GetComponents(True)

      For i = 0 To UBound(ComponentArray)

          Set Component = ComponentArray(i)

          If Component.GetSuppression = 0 Then

              MsgBox "State : Suppressed"

          Else

              MsgBox "Name:" & Component.Name2

              Set swCompModel = Component.GetModelDoc2

              If swCompModel.GetType = swDocASSEMBLY Then

                 MsgBox "Component" & Component.Name2

                 Set swsubAssy = swCompModel

                 subAssyCompArray = swsubAssy.GetComponents(True)

                 For j = 0 To UBound(subAssyCompArray)

                     Set SubAssyComp = subAssyCompArray(j)

                     If SubAssyComp.GetSuppression = 0 Then

                        MsgBox "State : Suppressed"

                     Else

                        MsgBox "Name:" & SubAssyComp.Name2

                     End If

                 Next j

              End If

          End If

      Next i

             

      End Sub

       

      Thank you