Code:
Sub CATMain()Dim oPartDocument as PartDocument
Dim oPart as Part
Dim oSel as Selection
Dim oBodies as Bodies
Dim oBody as Body
Set oPartDocument = CATIA.ActiveDocument
Set oSel = oPartDocument.Selection
Set oPart = oPartDocument.Part
Set oBodies = oPart.Bodies
Set oBody = oBodies.Item("Körper.2")
MsgBox GetPathOfBody(oBody,oSel)
End Sub
Function GetPathOfBody(oBody as Body, oSel as Selection) as String
'Delivers the path of the given body. The path is seperated by "\"
Dim oCurrentBody as Body
Dim i as Integer
Dim oCurrentBooleanOperation as BooleanShape
Set oCurrentBody = oBody
GetPathOfBody = oBody.Name
if Not oBody.InBooleanOperation then
exit function
end if
'search all Boolean operations: Assemble, Add and Remove
oSel.Search "(CATPrtSearch.Assemble + CATPrtSearch.Add + CATPrtSearch.Remove),all"
if oSel.Count2 = 0 then
exit function
end if
do while oCurrentBody.InBooleanOperation
for i = 1 to oSel.Count2
Set oCurrentBooleanOperation = oSel.Item2(i).Value
if oCurrentBooleanOperation.Body.Name = oCurrentBody.Name then
Set oCurrentBody = oCurrentBooleanOperation.Parent.Parent
GetPathOfBody = oCurrentBody.Name & "\" & oCurrentBooleanOperation.Name & "\" & GetPathOfBody
exit for
end if
next
loop
End Function