Macro: Selecting a component in an assembly

Hello

I would like to know the methods to select a component in an open assembly from a macro. And if possible the information associated with it, such as its file name, its folder, the type of document (part, assembly, etc.), etc. determine whether it is an instance, a repetition, a symmetry.

In summary, I would like to be able to select a component, perform an operation, select the next one, perform an operation, etc

Thank you

Hello

Looking at the Traverse Component: Traverse Assembly at Component Level Example (VBA) - 2021 - SOLIDWORKS API Help

 

2 Likes

Hello @Cyril.f 

It's perfect, thank you very much!

I still have to see how to determine if a component is a clone, a repetition or a symmetry and if I can do this other than by making name comparisons.

Hello

If I remember correctly, when it scans the feature manager, it lists the "designations" of the first level (it normally considers that a repetition is a tree element if I remember correctly) so we can simply exclude from the processing what starts with repetition, or even stop the processing as soon as we come across the constraints since anyway the repetitions are in under.

To know if it's a second occurrence, it seems to me that it also indicates the number of the occurrence, so just apply the treatment at that time.

1 Like

Thank you @Cyril.f 

Yes, in the absence of property or method that's what I thought I'd do for occurrences.

What's annoying is that it lists (crosses) the components in order of addition in the assembly (or not, since some instances (screws) are not even numbered in order) and not in the same order of appearance as in the tree. Would you know if there is a predestined way to choose the order in which to go through the components (order in the tree, alphabetical order, etc.)? It could save me loops of dissecting strings or reclassification.

I have to look but now I'm not going to have access to SW for 2 weeks.

I already made a macro of this type that listed in the order of the feature manager but I don't have it at hand and don't remember the method.