I would like to filter out surfaces whose air is less than a given value, for example y =2 m2 (like the green surface in the figure). I tried the scripts in C# and Python, it works but I get untrimmed surfaces instead of trimmed surfaces. With the item operator (for example i=101) I can find the trimmed surfaces but it boring and takes a lot of time each time the geometry changes.
You will find attached the rhino and grasshopper file to clearly see my problem.
with C#
private void RunScript(List x, double y, ref object A)
{
List filteredSurfaces = new List();
foreach (Brep brep in x)
{
{double area = brep.GetArea();
if (area < y)
{
filteredSurfaces.Add(brep.Surfaces[0]);
}
}
}
A = filteredSurfaces;
}
Hi @msgatrong, you likely want to iterate brep.Faces, measure the face Area and then filter out brep faces. A brep.Surface points to the underlying (untrimmed) surface of a brep face.
Thank you for your suggestion. I rewrote the script but it doesn’t work the function “brep.Faces[i].GetArea()” to get the air from the faces
private void RunScript(List x, double y, ref object A)
{
List filteredSurfaces = new List();
foreach (Brep brep in x)
{
int imax = brep.Faces.Count;
Console.WriteLine(“number of faces {imax}”);
for (int i = 0; i < imax ; i += 1)
{double area = brep.Faces[i].GetArea();
if (area < y)
{
filteredSurfaces.Add(brep.Faces[i]); //
}
}
}
A = filteredSurfaces;
}
You need to first convert brep.Faces[i] into a Brep with a single face using the method brep.Faces[i].DuplicateFace(False). The brep that DuplicateFace returns can be used to get area.
A Brep with a single face is what you are calling a “trimmed surface” . There is no such thing as a surface in a RhinoCommon document. There are only Breps. If a Brep has more than one face Rhino users call it a polysurface and if it has only one face it is called a surface (either trimmed or untrimmed).
After running your area test you may want to add the Brep that DuplicasteFace gave you to your list rather than the BrefFace.
This also works for me if you want to use .DuplicateFace and .GetArea():
#! python 2
import Rhino
def FilterBrepFaces(brep, y):
faces = []
for i, face in enumerate(brep.Faces):
area = brep.Faces[i].DuplicateFace(False).GetArea()
if area < y:
faces.append(face)
return faces
a = FilterBrepFaces(brep, y)
it filters out brep faces not breps though. I guess this is what was asked for in the OP.