How to catch points with a black color value in Rhinopython?

I’d like to identify points or text dots that have a black color or RGB (0, 0, 0). How do I go about identifying them?

I have used rs.ObjectColor, but it returns Color [Black] or Color [White] if I have not previously changed the color of that particular point previously. Is there a way to handle Color directly or as a variable?

Here is a sample of my current code:

 if rs.IsPoint(indiv) or rs.IsTextDot(indiv):
    index = 0
    if rs.ObjectColor(indiv) != (0, 0, 0, 0) or rs.ObjectColor(indiv) != Color [Black]: 
          print ('entered', rs.ObjectColor(indiv), rs.ObjectColor(indiv) != RGB(0,0,0))
          individual = 'ptWeight' 

So the goal of this snippet is to identify if a point (the GUID is inside the variable ‘indiv’) has been assigned a new color other than the default, black. If it has been assigned a different color, then it will assign the value ‘ptWeight’ to the variable individual. What’s the best way for me to go about catching points that are not the default color without having to base my output on a point inside Rhino? This would need this to work even without setting the checking condition to any points already inside the Rhino model.

This is always tricky. I use the following to make sure it works:

if color.R==0 and color.G==0 and color.B==0:
    #your object is black, do something...

Edit, apparently this will work better and more consistently in V6.


Yes, @Helvetosaur, we are making sure that you can create and compare colors and that colors are indexable with [0] = red, [1] = green, [2] = blue, [3] = alpha.

Yes, thanks, saw that YT item referenced in the “What’s new” in the latest WIP.

Cheers, --Mitch

Yeahp, this works perfectly. However, I’d like to ask what does rs.coercecolor do, exactly? Checked for the function in RhinoPython help in the editor, but I couldn’t find it.

This is an undocumented utility function. We’re working to document these for Rhino 6.

– Dale