Forum Discussion

kaiiii's avatar
Regular Contributor
9 months ago

How to get constant value based on RGB value.

How to get constant value based on RGB value.

data = RGB(255, 0, 0)

I want constant value of it through automation which is cLRed.

I need to perform  this from multiple colours. That's why I need a function  which can change value to constant.

2 Replies

  • Lolabuckley's avatar
    Occasional Visitor

    f you're trying to convert specific RGB values into constant names in a programming context, you can create a dictionary (or equivalent in your language) where RGB values are keys and constant names are values.  Tell Tims

    For example, in Python:  

    def rgb_to_const(r, g, b):
    color_dict = {
    (255, 0, 0): 'cLRed',
    (0, 255, 0): 'cLGreen',
    (0, 0, 255): 'cLBlue',
    # Add other colors as needed
    return color_dict.get((r, g, b), "Unknown Color")

    data = (255, 0, 0)
    print(rgb_to_const(*data)) # This will print "cLRed"   

    By using this approach, you can easily convert RGB values into the respective constant names. You can extend the color_dict dictionary to handle more colors as needed.

  • rraghvani's avatar
    Champion Level 3

    See Working With Colors


    You will have to get the integer value and perform a conditional statement to see if it matches with any of the constant values and return the colour. For example,

    switch (IntColour) {
      case clAqua:
         colour = BuiltIn.clAqua;
      case clCream:
         colour = BuiltIn.clCream;
      case clNavy:
         colour = BuiltIn.clNavy;

     There may be existing snippets of coding on the internet if you search for it.