import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def SelectMaterialColor():
    f = 1 + 2 + 4 + 8 + 16 + 32 + 256 + 512 + 4096 + 8192 + 1073741824
    obj_ids = rs.GetObjects("Select objects with target material colors", f, True, True, True)
    if not obj_ids: return
    
    colors = set()
    for obj_id in obj_ids:
        index = rs.ObjectMaterialIndex(obj_id)
        if index > -1:
            color = rs.MaterialColor(index)
            colors.add(color)
    
    rc = []
    for obj_id in rs.NormalObjects(True, False):
        index = rs.ObjectMaterialIndex(obj_id)
        if index > -1:
            color = rs.MaterialColor(index)
            if color in colors: rc.append(obj_id)
    
    if rc: 
        rs.EnableRedraw(False)
        rs.SelectObjects(rc)
        rs.EnableRedraw(True)
    
SelectMaterialColor()
