Assigning Display Colors to Surfaces Based on a List of Numbers

Hello everyone,
I’m currently working on a Grasshopper project where I have two lists of equal length. One list consists of numbers, such as [0, 1, 1, 2, 0, 1, 1, 3, 0, 1, 1, 0], and the other list contains corresponding surfaces.

I’m seeking assistance on how to dynamically assign display colors to these surfaces based on the numbers in my list. Each number should correspond to a specific color:

  • 0 should set the associated surface to white.
  • 1 should set the associated surface to black.
  • 2 should set the associated surface to blue.
  • 3 should set the associated surface to green.

For instance, in the example list of numbers mentioned above, the surface at index 0 should be displayed in white, the surface at index 3 in blue, and the surface at index 7 in green.

I’m open to suggestions on how to achieve this using GHPython or standard Grasshopper components. Any help, guidance, or sample scripts would be greatly appreciated.
@Mahdiyar I know you are an expert in GhPython and can help me!

Thank you for your assistance!

In your Python code, hardcode in a dictionary with 0, … , 3 as keys, and System.Drawing.Colour or RGB triples as values (12.0 KB)

1 Like

Thanks for your help, I don’t know whay but it didn’t work. it also didn’t show any errors.

Impossible to tell from just an image, as I have no idea what you are inputting into the script component. It is looking for a list of objects and a list of the same length of integers from 0 to 3.

1 Like

it was my fault. the type of numbers in my list was str. so i put them in ’ ’ and it worked. thanks alot<3