Add Brep problem

Hi all,

I have 4 curves, I create a brep from these curves, then add it to doc Object, but it returns Guid == 0000
Here is my code:

Brep rectangleBrep = new Brep();
rectangleBrep.AddEdgeCurve(curve1);
rectangleBrep.AddEdgeCurve(curve2);
rectangleBrep.AddEdgeCurve(curve3);
rectangleBrep.AddEdgeCurve(curve4);
Guid rbGuid = doc.Objects.AddBrep(rectangleBrep);
RhinoObject rhoRB = doc.Objects.Find(rbGuid);

rbGuid is null (and a Null Exception occurred). How to correct it?

Help me please,
Thanks!

Creating a Brep from scratch is quite difficult, but fortunately there are many static helper methods. In this case you may want to use Brep.CreateEdgeSurface using the four edges you have.

http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_Geometry_Brep_CreateEdgeSurface.htm

Thank you very much!

I’ve done, it was very good!