Can anyone show me how to do this with C#? I have a list of mixed Polysurfaces and Surfaces. Wanted to get the surfaces only. I know it’s easily done with native components but just for the sake of C# scripting…
Hi @Will_Wang,
Is this what you want?
private void RunScript(List<Brep> x, ref object A)
{
List<Surface> srfs = new List<Surface>();
foreach (Brep brep in x)
{
// Brep.IsSurface returns true if the Brep has a single face and
// that face is geometrically the same as the underlying surface.
if (brep.IsSurface)
srfs.Add(brep.Surfaces[0]);
}
A = srfs;
}
– Dale
Yes sir!
These “.IsSomething” properties are going to help me through the confusion of C# polymorphism.
Thanks!
Hi @Will_Wang,
Both Brep
and Surface
inherit from Rhino.Geometry.GeometryBase
. Thus if you have a list of Brep
objects, they will never be of type Surface
. Make sense?
– Dale
Gotcha
However I’m still getting nothing here. In my viewport you can see some of the strips are in fact two joined together. Naked edges are pink.
What could have gone wrong?
Hi @Will_Wang,
Read the comments in my sample code. If your Breps do not meet this requirement, then “no” will always be printed.
If you just want all of the underlying surfaces of a Brep, then you can do this:
private void RunScript(List<Brep> x, ref object A)
{
List<Surface> srfs = new List<Surface>();
foreach (Brep brep in x)
{
foreach (var s in brep.Surfaces)
srfs.Add(s);
}
}
– Dale
I thought I understood. But here you see I passed two Breps into the C# and a surface holder. The Brep on the left has two surfaces (tell by the thin white line, the interior edge), one on the right single surface. C# says neither of them passes .IsSurface but the surface holder clearly says one of them is a Surface.
Gotta be something I’m looking straight at but not noticing…
and this… I know C# is kinda compiled while Python is all interpreted but I think Python has won this battle
Hi @Will_Wang,
Brep.IsSurface
returns true if the Brep has a single face and that face is geometrically the same as the underlying surface (i.e. untrimmed). I can see from your panel that you have a trimmed surface. Thus Brep.IsSurface
will return false in this case.
– Dale
Ah! The trimmed surface is always the trouble maker. Makes sense. Thanks!
I guess this outta do it.