How to select objects by color inside grasshopper with ghpython or c#?

Hey there,

i want to build a simple geometry pipeline inside grasshopper.
The input should be a color (RGB) and the script should output every object with the color.

Maybe someone got a quick solution!

Thanks!

I guess you’re looking for FindByDrawColor method:

private void RunScript(Color color, ref object A)
{
  var objects = new List<GeometryBase>();
  foreach(var obj in RhinoDocument.Objects.FindByDrawColor(color, false))
    objects.Add(obj.Geometry);
  A = objects;
}
from Rhino.RhinoDoc import ActiveDoc
a = []
for obj in ActiveDoc.Objects.FindByDrawColor(color, False):
    a.append(obj.Geometry)

FindByDrawColor.gh (3.1 KB)

2 Likes

Although note that this will not update if an object in Rhino changes its colour. That plumbing is the heart of the Geometry Pipeline and it’s quite a lot of work to make sure you handle all the right events, but not too often and not when you’re not supposed to.

3 Likes