Brep.CapPlanarHoles does not work in C#

Hello everybody,

In a C# component for GH, I want to split a closed Brep into several closed Breps.
First I use the Brep.Split operation with the cutter I want. This works fine. It results in open Brep, that Ii want to close in a next step.
To do so, I used Brep.CapPlanarHoles but it does nothing.

What’s really annoying is that:

  • If I bake the open brep and use the Rhino command CapHoles it works perfectly
  • If I add the GH internal component Cap Holes, it also works.

The problem is that I want to do it all in C# for a bigger component.

Thanks a lot,
Nathanaël

PS: Here is the code
//Creation of the Brep

  • Point3d O = new Point3d(0, 0, 0);*

  • Point3d P = new Point3d(200, 40, 20);*

  • BoundingBox Bl_temp = new BoundingBox(O, P);*

  • Brep brep = Brep.CreateFromBox(Bl_temp);*

  • // Creation of the cutter for the lintel (initialisation)*

  • Vector3d x_vector = new Vector3d(200, 0, 0);*

  • Point3d L_1 = new Point3d(0, 0, -5);//Cutter extends a bit out of the layer (z-direction) to avoid problems when splitting*

  • Point3d L_2 = new Point3d(0, 0, 25);//Cutter extends a bit out of the layer (z-direction) to avoid problems when splitting*

  • List Points = new List();*

  • Points.Add(L_1);*

  • Points.Add(L_2);*

  • Curve line = Curve.CreateControlPointCurve(Points, 1);*

  • Surface Cutter = Surface.CreateExtrusion(line, x_vector);*

  • //Creation of the list of cutters*

  • List Cutters = new List (); //List of cutters*

  • for (int i = 0;i < 3;i++){*

  •  L_1.Y = L_1.Y + 10;*
    
  •  L_2.Y = L_1.Y;*
    
  •  List <Point3d> Points_temp = new List<Point3d>();*
    
  •  Points_temp.Add(L_1);*
    
  •  Points_temp.Add(L_2);*
    
  •  Curve line_temp = Curve.CreateControlPointCurve(Points_temp, 1);*
    
  •  Surface Cutter_temp = Surface.CreateExtrusion(line_temp, x_vector);*
    
  •  Cutters.Add(Cutter_temp.ToBrep());*
    
  • }*

  • A = Cutters;*

  • B = brep;*

  • //Cutting process*

  • Brep Brep_temp = brep.Split(Cutters, 1E-6);*

  • Brep bl_temp = Brep_temp[2];*

  • bl_temp.CapPlanarHoles(1E-6);*

  • C = bl_temp;*

Moved to Developer category

Hello
not very cool you didn’t post the Grasshopper Component.
In order to post code put 3 signs (on the 7 key on my keyboard)
image

For your problem you must use the output of bl_temp.CapPlanarHoles()

    Point3d O = new Point3d(0, 0, 0);
    Point3d P = new Point3d(200, 40, 20);
    BoundingBox Bl_temp = new BoundingBox(O, P);
    Brep brep = Brep.CreateFromBox(Bl_temp);
    // Creation of the cutter for the lintel (initialisation)*
    Vector3d x_vector = new Vector3d(200, 0, 0);
    Point3d L_1 = new Point3d(0, 0, -5);//Cutter extends a bit out of the layer (z-direction) to avoid problems when splitting
    Point3d L_2 = new Point3d(0, 0, 25);//Cutter extends a bit out of the layer (z-direction) to avoid problems when splitting
    List<Point3d> Points = new List<Point3d>();
    Points.Add(L_1);
    Points.Add(L_2);
    Curve line = Curve.CreateControlPointCurve(Points, 1);
    Surface Cutter = Surface.CreateExtrusion(line, x_vector);
    //Creation of the list of cutters*
    List<Brep> Cutters = new List<Brep> (); //List of cutters*
    for (int i = 0;i < 3;i++)
    {
      L_1.Y = L_1.Y + 10;
      L_2.Y = L_1.Y;
      List < Point3d > Points_temp = new List<Point3d>();
      Points_temp.Add(L_1);
      Points_temp.Add(L_2);
      Curve line_temp = Curve.CreateControlPointCurve(Points_temp, 1);
      Surface Cutter_temp = Surface.CreateExtrusion(line_temp, x_vector);
      Cutters.Add(Cutter_temp.ToBrep());
    }
    //A = Cutters;
    // B = brep;
    //Cutting process*
    Brep[] Brep_temp = brep.Split(Cutters, 1E-6);
    List < Brep > outputs = new List<Brep>();
    foreach (Brep bl_temp in Brep_temp)
    {
      if (bl_temp != null && bl_temp.IsValid)
      {
        outputs.Add(bl_temp.CapPlanarHoles(1E-6));
      }
    }

    C = outputs;

cut brep.gh (3.5 KB)

Hello Laurent,
Thanks a lot for the reply despite the bad quality of the post. To be honest, it’s my first post and I did not really saw where to share the GH component. That’s why I put (badly) the C# code. My next topic (if any) will be much better.

Thanks for the help. I understand the problem now. It’s really stupid… Anyway.

Have a nice day,

Nathanaël

hello
No it is not stupid it is also quite common. Sometimes function creates new objects sometime not. In rhinoceros cap is not creating new object.
Welcome to the C#