0

Is it possible to read the color of a CATBody? Something like:

   For Each myBody In myPart.Bodies
             myColor = myBody.Color 
    Next
Nic
  • 1,262
  • 2
  • 22
  • 42

1 Answers1

1

Yes, It's possible, but not exactly straight forward. The Color is available through VisProperties via a Selection. Also, this is one of those weird cases with the Catia API where you need to use late binding(I can't tell you why)

Here's an example:

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
GisMofx
  • 982
  • 9
  • 27
  • reason why you got those problems with early binding is, r, g, b are dimensioned wrongly, Dim r, g, b As Long means, r, and g are Variants, just b is Long, as .GetRealColor function expects longs, it wont allow you to pass variant as parameter, so, if you define rgb as Dim r As Long, g As Long, b As Long, youll be able to use early binding as well, and avoid to set vis first as well. – tsolina Mar 30 '16 at 17:09