AnsweredAssumed Answered

Get assembly top level components in correct feature tree order

Question asked by Jana Stahn on Feb 8, 2019
Latest reply on Feb 11, 2019 by Jana Stahn

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:

 

Name: B^getChildComponents-2

Name: C3-1

Name: E3-1

Name: B^getChildComponents-3

Name: B^getChildComponents-4

Name: E3-2

Name: E2^getChildComponents-1

 

But as you can see in the feature tree the correct order is this:

correctOrder.png

 

Any hints on how to actually get the correct order are appreciated!

Attachments

Outcomes