I must be overlooking something stupid here… I’m trying to see if an object color matches a predefined RGB color. My test - create a new blank file with one object in it which has color Rhino “Green” - RGB (0,255,0). Then run the following:
import rhinoscriptsyntax as rs
import System
objs=rs.NormalObjects()
color=rs.ObjectColor(objs[0])
print color==System.Drawing.Color.FromArgb(255,0,255,0)
By my way of thinking, the statement should be True, but it isn’t…
I can individually check R, G and B, but it seems like there should be something simpler that I’ve missed, or something I’m doing wrong here…
import rhinoscriptsyntax as rs
import System
objs=rs.NormalObjects()
color=rs.ObjectColor(objs[0])
print color.ToArgb()==System.Drawing.Color.FromArgb(255,0,255,0).ToArgb()
That is the integer number equivalent of the color, so in principle it should serve as a unique identifier.
The thing is, that a System.Drawing.Color object has a property Value - which should be this number, I think - it shows up in the debugger, but I can’t seem to get at that property in the usual way.
not sure if python changes this at all but for pure .net:
for system.drawing.color comparison uses not only the A,R,G,B values but other states of the color struct to compare (named color for one) so for example
Color.Black!=Color.FromARGB(0,0,0)
so even though both of those are ‘black’ and share same ARGB values they are not equal color structs.(one is ‘named’ black) so will return false when testing for equality. the …ToARGB method for testing to see if simply same ‘color’ for lack of better word I’ve found is reliable when dealing with the .net system.drawing.color