RhinoCommon C# Brep.CreatePlanarBreps

// Hello C# World!
One question : Someone knows how to fix this error : Error (CS0029): Cannot implicitly convert type ‘Rhino.Geometry.Brep’ to ‘Rhino.Geometry.Brep’ (line 90)forLoop-GridOfBreps.gh (10.1 KB) /

I will appreciate any explanation about how to use this method, thanks in advance!


private void RunScript(double x, double y, double z, int n, double w, double h, double g, ref object A, ref object B, ref object C, ref object D)
//Global variables
// x, y, z // Position
int nCells = n; // how many Breps
if (nCells < 1){nCells = 1;}
double width = w;
double height = width;
double gap = g; // space between

// Empty List to collect our geometry
List <Rectangle3d> gridRectangles = new List <Rectangle3d>();
List<NurbsCurve> myCurves = new List<NurbsCurve>();
List<Brep> myBrepSurfaces = new List<Brep>();
List<Extrusion> collectBreps = new List<Extrusion>();

// for loop to generete a 2D grid of Breps
for (int i = 0; i < nCells; i++)
  Point3d point = new Point3d((x + i * (width + gap)), y, z);
  Vector3d vectNormal = new Vector3d(Vector3d.ZAxis);
  Plane myPlane = new Plane(point, vectNormal);

  // Grid of of Rectangles
  Rectangle3d myRect = new Rectangle3d(myPlane, width, height);

  // Convert the Rectangles to Nurbs
  // https://developer.rhino3d.com/5/api/RhinoCommon/html/M_Rhino_Geometry_Rectangle3d_ToNurbsCurve.htm
  NurbsCurve myCurve = gridRectangles[i].ToNurbsCurve();

  // Create a Planar Brep Surface
  // Brep.CreatePlanarBreps Method
  // https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Brep_CreatePlanarBreps_5.htm
  Brep myBrepSurface = Brep.CreatePlanarBreps(myCurve, 0.001); // Why this line does not work?

  // Extrude NurbsCurve to a Closed Brep
  // https://developer.rhino3d.com/5/api/RhinoCommon/html/M_Rhino_Geometry_Extrusion_Create.htm
  double extrudeHeight = h;//1.0;
  Extrusion myExtrusion = Extrusion.Create(myCurve, extrudeHeight, true);

A = gridRectangles;
B = myCurves;
C = myBrepSurfaces;
D = collectBreps;


Line 91 & 92, replace with

Brep[] myBrepSurface = Brep.CreatePlanarBreps(myCurve, 0.001); // Why this line does not work?

Here is the preview:

The RhinoCommon Command mentions that it creates array of Breps,
You were assigning just Brep instead of Brep.
And since its an array
use myBrepSurfaces.AddRange(myBrepSurface) instead of myBrepSurfaces.Add(myBrepSurface.)


Thanks Su Lwpac! Best!

Su Lwpac

one question :

In this code myBrepSurfaces is a List of Brep
List myBrepSurfaces = new List();

And with this line:

Brep myBrepSurface = Brep.CreatePlanarBreps(myCurve, 0.001);

You get a Brep Array, right So the List.AddRange, allows us to add an Array inside the List?
It transforms an array into a List?


The addrange add an enumerable object for which an array is one. so you can use addrange to add each element of the array into the list.


Hi @andresobregonlopez, @christopher.ho has answered it properly. To Add to his explanation, Arrays are Variables which can hold multiple objects like Lists and the Way to add multiple objects to a list one needs to use AddRange() Function as explained by Christopher.

1 Like

Thanks @christopher.ho

Thanks @su.lwpac

using linq you can do it this way.

1 Like