如何只获得根级体

时间:2016-02-24 07:27:13

标签: vba catia

您是否有任何建议如何仅选择部分可见和根部的实体?例如,我希望只选择Lens - Outer Headlamp - LH - Clear and Lens - Outer Headlamp - LH - Black来自这个结构:

enter image description here

我试过

Dim objPart As part
Dim objBodies As Bodies
Set objPart = CATIA.ActiveDocument.part
Set objBodies = objPart.Bodies

和objBodies.Count的值是113,所以我直接在Catia中通过搜索命令尝试了它,而且我不能只获得那两个实体。你有什么想法吗?

1 个答案:

答案 0 :(得分:0)

最后我得到了答案:

Dim objPart As part
Dim objBodies As Bodies
dim rootBodiesCount as Integer
Set objPart = CATIA.ActiveDocument.part
Set objBodies = objPart.Bodies
rootBodiesCount = getRootBodiesCount(objBodies)

Function getRootBodiesCount(allBodies as Bodies) As Integer
  getRootBodiesCount = 0
  For i = 1 To allBodies.Count
    Dim inBool As Boolean: inBool = allBodies.Item(i).InVooleanOperation
    Dim visibility As Boolean: visibility = allBodies.Item(i).Visible
    If inBool = False Then
      If visibility Then getRootBodiesCount = getRootBodiesCount + 1
    End If
  Next
End Function