Get colours of Brep in C# Grasshopper plug-in

Sounds simple but no luck so far. I hope this isn’t a “Do my work for me” question. I’m building a C# plugin for Grasshopper. Model data comes into the plug-in from Rhino as follows:
pManager.AddBrepParameter(“intSurf”, “intSurf”, “intSurf”, GH_ParamAccess.list);
then, in SolveInstance I declare:
List iFaceList = new List();
and call:
DA.GetDataList(2, iFaceList);

I’m trying to pass acoustical information about the model via the RGB codes. I can get that for layers in general:

        Rhino.RhinoDoc thisDoc = Rhino.RhinoDoc.ActiveDoc;
        int absCoef1 = thisDoc.Layers.FindName("Seats").Color.G;
        int absCoef2 = thisDoc.Layers.FindName("GypsumBoard").Color.G;

But I need the RGB codes for each surface, i.e. each of my Breps in what I’ve called iFaceList. Is RGB information no longer available in a Brep? How can I dig deeper into the Doc information?

Any help will be most appreciated.

John O’Keefe

P.S. I’ve also tried the following:

        IGH_GeometricGoo goo = (IGH_GeometricGoo)iFaceList[1];
        int lIndex = doc.Objects.Find(obj).Attributes.LayerIndex;
        int lIndex = iFaceList[1].ObjectT;
        Rhino.RhinoDoc thisBrep = Rhino.DocObjects.RhinoObject();
        int colour = Rhino.DocObjects.RhinoObject(iFaceList[1].A);

Which I got from a very old post on this forum. But it fails on the first line.


I totally didn’t understand what you asked for… :sweat_smile:
This is from the title alone:

2020-06-04 22_06_37-Window

private void RunScript(Guid guid, ref object A)
    Rhino.DocObjects.RhinoObject obj = this.RhinoDocument.Objects.FindId(guid);
    A = obj.Attributes.ObjectColor;

Hi Riccardo.

Perhaps the P.S. addition has confused the issue. It works on its own as a plug-in but it relies on the outdated:

pManager.Register_GeometryParam(“Geometry”, “G”, “Geometry to examine”);

to get the geometry into the C# code. All I want to do is get the colour of a Brep once it’s in as a Brep. The updated version of Register_GeometryParam (pManager.AddGeometryParameter) doesn’t work either.

But like I said, this is probably a distraction. The real issue is simple. Given a Brep, how do I get its attributes (e.g. colour) in my C# routine.

Thanks for your help Riccardo.


I don’t have much knowledge in this matter, but i think a “brep” don’t contain colour properties.

This seems relevant

If you only have a brep then you can’t. An object in a Rhino document is made up of geometry and attributes. The geometry is just the shape (point, curve, brep, etc.) with optional user data, the attributes contain the layer, name, color, grouping, line type etc.

Grasshopper doesn’t deal in attributes, only geometry. However a brep which has been imported from a RhinoDoc will still have a reference guid which you can use to look up the original object and harvest its attributes. For this to work your component needs to get the data not as type Brep but as GH_Brep.

As soon as a GH_Brep is modified however, that guid is stripped and you’ll never be able to work out where it came from.

1 Like

Thanks David.

I suspected it was something like that. I didn’t know about GH_Brep though. I’ll give it a try.

Thanks for your contribution. You guys sure do keep on top of things!

Thanks for this David. I managed to get the RGB colour codes into the C# routine and everything works fine. I thought I should share the eventual solution to the problem with the group. I shall explain.

What I’m trying to do is calculate reflected sound inside a room (i.e. a collection of Breps). For that I need each surface to have an acoustic absorption coefficient. This is passed from the Rhino model into the C# plug-in via the RGB colour code of the surfaces in the Rhino model. So, for example, a surface with an RGB colour of (0,10,0) has an absorption coefficient of 0.10 and a surface with an RGB code of (0,85,0) will have a coefficient of 0.85. The problem is that bringing the Breps into the C# code using “pManager.AddCurveParameter” does not, as David has pointed out, include information like the material or colour codes.

The solution is now buried deep in my code, which it too long to go into here. So, what I’ve done for the group instead, is build a simple plug-in that takes an RGB colour coded object, retrieves the colours and leaves you with the integer RGB codes and the kind of Breps that Rhinocommon feels more comfortable with.

The C# code is attached as file name: BrepColoursComponent.cs

I hope all this helps.

John O’Keefe

BrepColoursComponent.cs (3.1 KB)