I checked similar questions in the forum, but they all give the same answer (see e.g. Traverse Assembly VBA does not show components in the correct order! , Get components name from an assembly in a specific order VBA , Solidworks API: Get components in order as they appear in FeatureManager ):
- traverse the tree by using IModelDoc2.GetFirstFeature/IComponent2.GetFirstFeature and IFeature.GetNextFeature,
- find the components either by using IFeature.GetTypeName2 or by IEntity.GetType,
- retrieve the components by using IFeature.GetSpecificFeature2.
But: It does not work. In the attached assembly, this approach does NOT give the order as it is given in the feature tree.
(See API Help, IModelDoc2.FirstFeature: "This method returns features in the model definition order, which is not the same as the order displayed in the user interface. See ITreeControlItem for details.")
To see that, just open the attached "getChildComponents.SLDASM", edit the macro "getComponentsOrdered.swp" (EDIT because the output will be in the console which is not seen if you directly run it), select the root component and run the macro. The output will be:
But as you can see in the feature tree the correct order is this:
Any hints on how to actually get the correct order are appreciated!