How to check object's RGB color in python "proper" way?

How dumb is this?

if str(rs.ObjectColor(Pick[0])) == “Color [A=255, R=255, G=220, B=170]”:

oc = rs.ObjectColor(Pick[0])
if oc.R==255 and oc.G==220 and oc.B==170 and oc.A==255:
    # success

note 1: whenever you are working on some type you are not certain of what it provides you I suggest you put in a print dir(instanceofsomething). It’ll give you valuable information.

note 2: in theory one should be able to use something like

import System.Drawing as sd

oc = rs.ObjectColor(Pick[0])
col = sd.Color.FromArgb(255, 255, 220, 170)
print oc==col

but sometimes the == operator fails, especially in cases where a color is one of the predefined ones, but the numbers otherwise match. For instance set display color for object to the Red from the drop down. In the code set up col = sd.Color.FromArgb(255,255,0,0). The == test returns False, even though both colors have the same values in their channels. Hence the original snippet comparing each channel separately.

2 Likes

So, there isn’t a more elegant thing like RhinoScript’s RGB (255, 255, 255)?

Re: note 1. I usually just use print, but that’s event better. Thanks!

That’d be the Color.FromArgb(255, 255, 220, 170) in my sample.

Yeah I noticed on predefined colors rs.ObjectColor() spits out just color name.