如何在CATIA VBA宏中获取Body Color?

时间:2015-12-03 16:47:23

标签: vba catia

是否可以读取CATBody的颜色?类似的东西:

   For Each myBody In myPart.Bodies
             myColor = myBody.Color 
    Next

1 个答案:

答案 0 :(得分:1)

是的,这是可能的,但不是直截了当的。可以通过VisProperties通过Selection获取颜色。此外,这是使用Catia API的那些奇怪案例之一,您需要使用后期绑定(我不能告诉您原因)

以下是一个例子:

Option Explicit
Sub BodyColors()

Dim sel As Selection
Dim selected As SelectedElement
Dim vis As Variant 'VisPropertySet 'This must be variant for late binding. Otherwise you get an error.
Dim RGB(3) As Long 'or you can use an array
Dim r, g, b As Long


Dim myPart As Part
Dim myBody As Body

Set myPart = CATIA.ActiveDocument.Part
Set sel = CATIA.ActiveDocument.Selection
For Each myBody In myPart.Bodies
    sel.Clear
    sel.Add myBody
    Set vis = sel.VisProperties
    vis.GetRealColor r, g, b 'you must pass the values into the function
    Debug.Print myBody.Name & ": "; r & "," & g & "," & b
Next
sel.clear
End Sub