AnsweredAssumed Answered

Solidworks API: Get components in order as they appear in FeatureManager

Question asked by Mitch Najmitch on Aug 19, 2015
Latest reply on Aug 19, 2015 by Mitch Najmitch

Hi, I am trying to get all the components (parts and assemblies) from the root assembly. I wan't the components to be in the order as they appear in the FeatureManager tree.


Using the API quide a wrote macro posted bellow. Problem is, that call to entity.GetComponent allways returns Nothing. Can please anyone help me with this?


Thank you




Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swFeat As SldWorks.Feature

Dim entity As entity

Dim component As Component2



Sub main()


    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc


    Set swFeat = swModel.FirstFeature


    While Not swFeat Is Nothing


        Set entity = swFeat


        If entity.GetType = swSelectType_e.swSelCOMPONENTS Then


            Set component = entity.GetComponent


            MsgBox "Name: " & component.Name2


         End If

         Set swFeat = swFeat.GetNextFeature


End Sub