Make Python Script: Get Brep Edges

Hey guys,
I am trying to get familiar with Python scripting to write my own little components. I want to slowly dive into this topic by converting this small script into a component: I have a surface, that I want to extrude by a certain height and get all edges as curves.
BrepEdges.gh (4.8 KB)

Do you have a hint for me how to tackle this?
Best
Max


Try to translate this C# (Given a List of Breps: bList, a double d and a bool bothsides)

 bList = bList.Where(x => x != null && x.IsValid).ToList();
    if(!bList.Any())return;

    breps = new DataTree<Brep>();
    edges = new DataTree<Curve>();

    for(int i = 0; i < bList.Count;i++){
      Thicken(i, bList[i], d, bothsides);
    }
public DataTree<Brep> breps;
  public DataTree<Curve> edges;

  static double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

  public void Thicken(int idx, Brep brep, double d, bool bothsides){

    for(int i = 0; i < brep.Faces.Count;i++){
      BrepFace face = brep.Faces[i];
      Brep thick = Brep.CreateFromOffsetFace(face, d, tol, bothsides, true);
      breps.Add(thick, new GH_Path(idx, i));

      var be = thick.Edges;
      int b = 0;
      foreach(BrepEdge e in be){
        edges.AddRange(e.DuplicateSegments(), new GH_Path(idx, i, b));
        b++;
      }
    }
  }

Notify if you want connectivity as well (faces, edges, vertices, cats and dogs)

import rhinoscriptsyntax as rs

curves = rs.ExplodeCurves(x)

Create a list to store the extruded geometry

extruded_geometry =
for curve in curves:
if curve:
extruded_curve = rs.ExtrudeCurveStraight(curve, (0,0,0), (0,0,y))
if extruded_curve:
extruded_geometry.append(extruded_curve)
# Output the extruded geometry

if extruded_geometry:
d = extruded_geometry
else:
d = None

I managed this so far: I can get it to make surfaces, but somehow I cant create the edges of each surface

BrepFace_Thicken_V1.gh (15.8 KB)

BrepFace_Thicken_V1A.gh (133.4 KB)

BTW: A “surface” like the one that you posted is a BrepFace (a trimmed Suface is a Brep with a single BrepFace. Any BrepFace has an outer Loop (as Curve) and maybe inner Loops (as Curves) - i.e. holes). So in RC the required Methods ARE NOT in the Surface/NurbsSurface Classes.

BTW: A Brep (kinda a Mesh) is a mini DataBase where Faces, Edges, Vertices (and cats/dogs) are related via ConnTrees (3 classes thus 9 possible combos):

Thanks! I will check it out!

Spend 5 minutes more for some “show” C#

BrepFace_Thicken_V1B.gh (130.6 KB)

I am sorry but I don’t really understand your file, I see so much stuff. Only thing I was looking for is to get a list of curves from a planar surface

Stuff used is the MINIMUM imaginable (if we forget the rnd thicken dist). With regard the Show C# … well … it’s rather obvious why is added.

Some tips:

  1. ALWAYS try to deal with the general case (and try to manage your strategy accordingly).
  2. ALWAYS use an option for a more “explicit” classification (for instance taking into account the Faces enumeration [not to mention the Loop Type]: this means a Tree as an output).
  3. ALWAYS try to know what sort of animal you have on hand AND what to expect (for searching suitable Classes/Methods [and their syntax] in RC ).
  4. NEVER deal with an isolated object (like your Face). In 99.9999999% of real-life cases objects belong to collections (Lists/Trees/Arrays and the likes).

BrepFace_Thicken_Help.gh (14.9 KB)

I managed to do it like this:

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
import Grasshopper as gh

First Component Logic

curves = rs.ExplodeCurves(lower_floor_curve)

Create a list to store the extruded geometry

extruded_geometry =
for curve in curves:
if curve:
extruded_curve = rs.ExtrudeCurveStraight(curve, (0,0,0), (0,0,floor_height))
if extruded_curve:
extruded_geometry.append(extruded_curve)
# Output the extruded geometry

if extruded_geometry:
wall_surfaces = extruded_geometry
else:
wall_surfaces = None

Extract all edge curves from wall_surfaces and then explode them

edge_curves_list =

for surface in wall_surfaces:
edge_curves = rs.DuplicateSurfaceBorder(surface)
if edge_curves:
for edge_curve in edge_curves:
segments = rs.ExplodeCurves(edge_curve)
if segments:
edge_curves_list.extend(segments)