9 Replies Latest reply on Apr 6, 2017 1:43 PM by Deepak Gupta

    Creating a list of components in an assembly

    Habib Ghalamkari

      I'm trying to write a macro that creates a list of all components in an assembly and does some actions on each one.

      As you see in the following images, the list that macro gives me is not in the order of the components in feature manager.

      How can I have the given list match the order of the components in feature manager.

       

      thanks for any kind of help.

       

      2017-04-05_16-48-24.jpg

       

      2017-04-05_16-46-58.jpg

      this is the macro:

       

      Option Explicit

          Dim swApp               As SldWorks.SldWorks

          Dim swModel             As SldWorks.ModelDoc2

          Dim swFeat              As SldWorks.Feature

          Dim swCustPropMgr       As SldWorks.CustomPropertyManager

          Dim strValue0           As String

          Dim strValue1           As String

          Dim strValue2           As String

          Dim strValue3           As String

          Dim strValue4           As String

          Dim strValue5           As String

          Dim swBodyFolder        As SldWorks.BodyFolder

       

      Sub main()

          Dim swModel As ModelDoc2

          Dim swModel_Assy As ModelDoc2

          Dim vComps As Variant

          Dim swComp As SldWorks.Component2

          Dim swAssy As SldWorks.AssemblyDoc

          Dim i As Integer

          Dim PN As String  

          Dim Result As String

         

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

          Set swModel_Assy = swApp.ActiveDoc

         

          If swModel.GetType = swDocASSEMBLY Then

              Set swAssy = swModel

              vComps = swAssy.GetComponents(False)

              For i = 0 To UBound(vComps)

                  Set swComp = vComps(i)

                  Set swModel = swComp.GetModelDoc2

                  Debug.Print swModel.GetTitle

                ' some actions here .....

              Next i

          End If

       

      End Sub