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?
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.
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.
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