I'm not really sure I understood you but I hope this answers helps.
1. Use GetComponents Method (IAssemblyDoc). Ideally the variable to which you assign the return of this method should be a variant.
2. Define a Component2 variable and traverse the variant and from its lbound (lower bound) to its ubound (upper bound) assigning the traversed element to the Component2 variable on every iteration. Add an if condition (for the next step) that checks if Component2:Name2 contains "<1>". This condition will make sure you only get first instances of Component2.
3. Use Component2::GetBodies3 to get the bodies. Ideally the variable to which you assign the return of this method should be a variant.
4. I would suggest creating a custom class: A strongly typed collection of body and its corresponding components2. Add bodies to this collection as you traverse the bodies variant.
It would helpful if you can explain further what you want to do with bodies to get a concise answer.
Thank you for your help,
I am developing a C# SolidWorks task pane addin which flattens this sort of anarchical feature manager tree view:
to a custom tree view:
- Part1 (2 components)
- CutList1 (3 bodies)
- CutList2 (1 body)
- Part2 (3 components)
- CutListA (2 bodies)
- CutListB (5 bodies)
Note: Assembly is supposed fully resolved and SubAssembly(ies)/Folder(s) become invisible.
This tool is a custom bill of material manager with specific functions.
My objective is to:
- Select all CutList1 bodies of all Part1 components in the Assembly context if I click on CutList1 tree view item.
What I need to understand is:
- Is two distinct components sibling a same document have a GetModelDoc2 method returning a same object reference?
- If GetModelDoc2 method returns same reference, Body2 references of two distinct components will be the same?
- Is two corresponding bodies of two distinct components sibling a same document have a same Id/Persistent Id?
- What are the different members of corresponding objects of two distinct components sibling a same document?
- There is a way to reference them simply?