×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Setting body color RGB with an array

Setting body color RGB with an array

Setting body color RGB with an array

(OP)
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()


RE: Setting body color RGB with an array

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
http://scripts4all.eu/txtoncurve/ - Text along a curve for Catia V5

RE: Setting body color RGB with an array

(OP)
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

RE: Setting body color RGB with an array

What kind of error do you get? Anyway, you have a mistake in the last line, you are calling SetRealColor with 3 arguments only.

Tesak
http://scripts4all.eu/txtoncurve/ - Text along a curve for Catia V5

RE: Setting body color RGB with an array

(OP)
There is no error, it cycles through all the selections without changing the color.

RE: Setting body color RGB with an array

Change it like this:

CODE --> VBA

.
.
.

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
http://scripts4all.eu/txtoncurve/ - Text along a curve for Catia V5

RE: Setting body color RGB with an array

(OP)
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.

RE: Setting body color RGB with an array

To start over use this:

CODE --> VBA

If i > Ubound(RGB) Then i = 0
i = i + 1 

Tesak
http://scripts4all.eu/txtoncurve/ - Text along a curve for Catia V5

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources

eBook - Efficient and Effective Production Support with 3D Printed Jigs and Fixtures
Jigs and fixtures offer manufacturers a reliable process for delivering accurate, high-quality outcomes, whether for a specific part or feature, or for consistency across multiples of parts. Although the methodologies and materials for producing jigs and fixtures have evolved beyond the conventional metal tooling of years past, their position as a manufacturing staple remains constant due to the benefits they offer. Download Now
Overcoming Cutting Tool Challenges in Aerospace Machining
Aerospace manufacturing has always been on the cutting edge, from materials to production techniques. However, these two aspects of aerospace machining can conflict, as manufacturers strive to maintain machining efficiency with new materials by using new methods and cutting tools. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close