Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting body color RGB with an array

Status
Not open for further replies.

LucasC

Automotive
Feb 18, 2019
157
US
Hello,

I'm trying to develop some code that changes all the part bodies in a CATPart with a group of RGB values. I'm trying to do this with an array but its not functioning correctly. It cycles through the structure and selects each body as intended but does not change the color. I believe its the way I have the values defined in the array:

Dim RGB(21)
RGB(0) = "234,234,234,0"
RGB(1) = "30,49,130,0"
RGB(2) = "147,155,161"
...etc

...For next
Set vis = sel.VisProperties
vis.SetRealColor RGB()


 
Replies continue below

Recommended for you

Hi LucasC,
sub SetRealColor (long iRed, long iGreen, long iBlue, long iInheritance) expects 4 long values, but you are providing 1 string value. Change your array like this:

RGB(0) = Array(234, 234, 234, 0)
RGB(1) = Array(255, 255, 255, 1)
.
.
.

and then call it in a loop this way: vis.SetRealColor RGB(0)(0), RGB(0)(1), RGB(0)(2), RGB(0)(3)

Tesak
- Text along a curve for Catia V5
 
No luck with :
Dim RGB(21)
RGB(0) = Array(234, 234, 234, 0)
RGB(1) = Array(30, 49, 130, 0)
RGB(2) = Array(147, 155, 161)
'...etc

Dim visprop As Variant
Dim sel1 As selection
Dim Part1 As Part
Set Part1 = CATIA.ActiveDocument.Part

Set sel1 = CATIA.ActiveDocument.selection
Dim myBody As Body
For Each myBody In Part1.Bodies
sel1.Clear
sel1.Add myBody
Set visprop = sel1.VisProperties
visprop.SetRealColor RGB(0)(0), RGB(0)(1), RGB(0)(3)
Next
 
There is no error, it cycles through all the selections without changing the color.
 
Change it like this:

Code:
.
.
.

Dim myBody As Body
Dim i As Long
For Each myBody In Part1.Bodies
    sel1.Clear
    sel1.Add myBody

    Set visprop = sel1.VisProperties
    visprop.SetRealColor RGB(i)(0), RGB(i)(1), RGB(i)(2), RGB(i)(3)

    i = i + 1
Next

Tesak
- Text along a curve for Catia V5
 
Yes, I noticed I had the RGB item index mis-labeled and it colored all the bodies the same, which made me realize i needed to index the RGB +1

How can I make it start over if the number of part bodies exceeds the array value count?

thanks in advance I'm still a beginner.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top