Getting a reference to a component body selected from the FeatureManager tree
Posted: Sun Oct 01, 2023 9:24 am
Hi,
I am writing a macro that needs to collect references to solid bodies (Body2 objects) that user may select in an assembly environment through different ways, for example:
1) Select a component itself from a FeatureManager tree;
2) Select a body face from the graphics area;
3) Select a body from the component (part) Solid Bodies folder.
It is extremely important to get a reference to a Component body, not just ModelDoc2 body. This is because there may be multiple instances of that component in the assembly, and I need a body reference from that specific component instance which the user intended to select, because I will need to retrieve it's positional and rotational data in the assembly through MathTransform. To achieve this, I covered the first two selection cases like this:
1) If component is selected, macro gets references to all bodies within selected component by running GetBodies3 on Component2. Boom, done.
2) If face is selected, macro gets the name of the selected body by running GetBody on the selected Face2. Then, it converts that Face2 to Entity, and runs GetComponent on that Entity to get the component reference. Then again it runs GetBodies3 on it to retrieve a full list of bodies, and runs a simple foreach loop to find the body which matches the name retrieved initially.
However, for the third case - when the user selects a body directly from the Solid Bodies folder - I mean like this:
...Then I'm at a loss. I can't figure out any way to determine from which specific component instance did the user select that body. Is there any way to get that reference?
I am writing a macro that needs to collect references to solid bodies (Body2 objects) that user may select in an assembly environment through different ways, for example:
1) Select a component itself from a FeatureManager tree;
2) Select a body face from the graphics area;
3) Select a body from the component (part) Solid Bodies folder.
It is extremely important to get a reference to a Component body, not just ModelDoc2 body. This is because there may be multiple instances of that component in the assembly, and I need a body reference from that specific component instance which the user intended to select, because I will need to retrieve it's positional and rotational data in the assembly through MathTransform. To achieve this, I covered the first two selection cases like this:
1) If component is selected, macro gets references to all bodies within selected component by running GetBodies3 on Component2. Boom, done.
2) If face is selected, macro gets the name of the selected body by running GetBody on the selected Face2. Then, it converts that Face2 to Entity, and runs GetComponent on that Entity to get the component reference. Then again it runs GetBodies3 on it to retrieve a full list of bodies, and runs a simple foreach loop to find the body which matches the name retrieved initially.
However, for the third case - when the user selects a body directly from the Solid Bodies folder - I mean like this:
...Then I'm at a loss. I can't figure out any way to determine from which specific component instance did the user select that body. Is there any way to get that reference?