Brep Edges in C#

I’m writing a C# script to do Ice-ray latices, a classical example of a shape grammar. I have done the surface (brep) subdivision part and I’m now trying to offset the brep edges inward. After offsetting them I need to trim the Brep with the new boundary.

Brep.Curves3D is giving me the curves of the untrimmed surface. How do I get the Trimmed Surface edges?

Maybe try Brep.Loops.Select(l => l.To3dCurve()) to convert the BRep loops to curves.

I’m curious to see the final result of this shape grammar, interesting topic!

Thanks, I’ll share it when it’s done.
I don’t know what I am missing! I can only get the edges of the untrimmed face.

Here is what I’ve tried:

1 - Returns the edges as curves of the untrimmed face of the brep (at origin)
2 - Returns the edges as curves of the untrimmed face of the brep (in place)
3 - Returns the edges as a polyline of the untrimmed face of the brep (in place)
4 - Returns the edges as a polyline of the untrimmed face of the brep (in place)

Brep brp = aSup.ToBrep();
    List<Curve> listaCrv = new List<Curve>();
    
    //1 - listaCrv.AddRange(brp.Trims.Select(l => l.ToNurbsCurve()));
    //2 - listaCrv.AddRange(brp.Curves3D);
    //3 - listaCrv.AddRange(brp.Loops.Select(l => l.To3dCurve()));
    //4 - for(int i = 0;brp.Faces.Count > i;i++)
    //{
    //  listaCrv.AddRange(Curve.JoinCurves(brp.Faces[i].DuplicateFace(true).DuplicateEdgeCurves()));
    //}


    A = listaCrv;

offsetbrepedges.3dm (24.8 KB)
OffsetBrepEdges.gh (5.6 KB)

You reference the input trimmed surface as a “Surface” not as a “BRep” (right-click, type hint).

A Surface is always untrimmed. A single trimmed surface is always a BRep.

Ok, so it strips the trims and only keeps the surface. I should have know! Thanks for your quick reply!

Thanks for you help, I managed to do what I wanted. It now looks like this:

private void RunScript(Brep aSup, double offSet, ref object A)
  {
    Brep brp = aSup;
    CurveList listaCrv = new CurveList();
    listaCrv.AddRange(brp.Loops.Select(l => l.To3dCurve()));

    List<Curve> offsetCrv = new List<Curve>();

    foreach(Curve crv in listaCrv){
      Rhino.Geometry.AreaMassProperties centro = Rhino.Geometry.AreaMassProperties.Compute(crv);
      Point3d ptCentro = centro.Centroid;
      double param;
      crv.ClosestPoint(ptCentro, out param);
      Point3d ponto = crv.PointAt(param);
      Vector3d normal = new Vector3d(ponto.X - ptCentro.X, ponto.Y - ptCentro.Y,
        ponto.Z - ptCentro.Z);
      Curve[] crv1 = crv.Offset(ptCentro, normal, offSet, 0.001, CurveOffsetCornerStyle.Sharp);
      offsetCrv.AddRange(crv1);
    }

    A = offsetCrv;

  }

It works, but my experience with IceRay lattices in grasshopper tells me that there can be a lot of problems caused by small edges when offsetting the outlines. Is there any method to ignore edges smaller than a certain length?
These curves are going to be used for digital fabrication with a CNC router. So, another thing I must do is to fillet the corners. Offset has an option to have rounded corners, but is there a way to control the radius?

@menno I’ve completed the script but I’m getting invalid curves with some breps and I can’t figure out why. The trimmed surfaces look ok when on rhino, but I get an invalid curve after I run Brep.Loops.Select(l => l.To3dCurve()). I’ve commented out the curve extraction of the script and tried to extract the boundary curves with rhino and I had no problem.
Any ideas?

Thanks!
C#_IceRay3.gh (11.4 KB)