How do I get the Aggregated Bodies from a CATPart in CATIA API's?

3.3k views Asked by At

I am able to write recursive subroutines that cycle thru all the Geometrical Sets and Ordered Geometrical Sets without issue, because there is a collection under each GS and OGS for HybridBodies and OrderedGeometricalSets, respectively. However, when I find the Part-Level (Root-Level) Bodies, there is not a Bodies collection inside it. So, when I have a model with multiple aggregated Boolean operation Bodies inside of a body, I can't find them in the standard collections operation in VBA, C#.net, or VB.net.

How can I find these Bodies inside of a Body?

2

There are 2 answers

0
Nicholas Pisca On BEST ANSWER

This took a while to figure out, and I'm definitely posting it on the web because it's barely documented.

The problem with Bodies automation is the fact that all bodies are stored in the part level collection. I didn't see that at first, because I'm used to the Geometrical Set and OGS recursion when working with CATIA spec tree navigation.

But the fact that all bodies are stored in the root level collection is actually more of a hindrance than a benefit, because it does not allow for recursive cycling.

I tried to use the selection object searching to find aggregated bodies, but it was too buggy and cumbersome to figure it out.

The best solution for determining if a Body is aggregated via Boolean solids operation in another Body is to use the "InBooleanOperation" method. This is not very well documented and that's why I'm posting it here.

It returns a simple true or false. Like this:

            Body CurB = MyBodies.Item(x);
            Boolean InBoolOpp = CurB.InBooleanOperation;
            if (InBoolOpp == false)
            {
                    // Code here
            }

As for finding the parent of a nested Body, I haven't figured it out yet, but I'll post it once I do.

5
Lardman363 On

You are correct, all bodies are viewed as being at the root of the specification tree. In VBA you can select a body then search for bodies inside. So use the .InBooleanOperation property first to see if the body is at the root of the tree...if it is, Select it and search for other bodies inside with the code below.

Dim oPartDoc as PartDocument
Set oPartDoc = CATIA.ActiveDocument

Dim oPart as Part
set oPart = oPartDoc.part

Dim oSelection as Selection
Set oSelection = oPartDoc.Selection

Dim cBodies as New Collection

Dim oBody As Body
Set oBody = oPart.Bodies.Item(1)

oSelection.Clear
oSelection.Add oBody 'Add the body to the selection object
oSelection.Search "Type=Body,sel" 'Search in the selected object
'All bodies in the selected body are added to the selection object
'Loop through selected bodies and add to collection
For i = 1 to oSelection.Count
     cBodies.add oSelection.Item(i).Value
Next