# Brep for Planar Rectangular Surface returns 5 edges

**URL:** <https://discourse.mcneel.com/t/brep-for-planar-rectangular-surface-returns-5-edges/74990>\
**Category:** Scripting\
**Tags:** rhinocommon, rhinoscriptsyntax\
**Created:** [November 18, 2018, 4:15am UTC](https://discourse.mcneel.com/t/brep-for-planar-rectangular-surface-returns-5-edges/74990 "2018-11-18T04:15:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MClare](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mclare/32/84707_2.png) [@MClare](https://discourse.mcneel.com/u/MClare)\
**Post date:** [November 18, 2018, 4:15am UTC](https://discourse.mcneel.com/t/brep-for-planar-rectangular-surface-returns-5-edges/74990/1 "2018-11-18T04:15:11Z")

</div>

I’m trying to get the edges of a planar surface that _should_ be a rectangle, so I’m expecting a return of 4 edges. For some of the geometry I’m dealing with however, I’m getting 5 edges (my guess is due to a tolerance issue), which causes problems for the rest of my script. Is there a good way to “force” my brep to only have 4 edges (i.e. approximate as a rectangle if it is slightly off)?

```auto
strips = rs.ObjectsByLayer('CSA')
for strip in strips:
    # get only surfaces
    if rs.IsSurface(strip):
        if rs.IsSurfacePlanar(strip):
            strip_brep = rs.coercebrep(strip)
            edges = Rhino.Geometry.Brep.DuplicateEdgeCurves(strip_brep)
            print(len(edges))

```

---

<div class="post-metadata">

**Author:** ![Willem](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/willem/32/554347_2.png) [@Willem](https://discourse.mcneel.com/u/Willem)\
**Post date:** [November 18, 2018, 12:07pm UTC](https://discourse.mcneel.com/t/brep-for-planar-rectangular-surface-returns-5-edges/74990/2 "2018-11-18T12:07:04Z")

</div>

Hi MClare,

Best would be to first see and find what those edges are.  
If you `import scriptcontext as sc`

you can add the lines:

```auto
        if len(edges) != 4:
            for edge in edges:
                sc.doc.Objects.AddCurve(edge.EdgeCurve)

```

this way wuou can find the unexpected 5th edge and maybe fix the issue beforehand or setup a filtering or fix for these 5 edge surfaces.

-Willem

---

<div class="post-metadata">

**Author:** ![MClare](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mclare/32/84707_2.png) [@MClare](https://discourse.mcneel.com/u/MClare)\
**Post date:** [November 18, 2018, 3:52pm UTC](https://discourse.mcneel.com/t/brep-for-planar-rectangular-surface-returns-5-edges/74990/3 "2018-11-18T15:52:01Z")

</div>

Hi Willem,

I discovered that the input geometry that was used to initially construct the surface (and then the Brep) consisted of a polyline made of 6 points (4 corners and 2 midpoints). I’m not sure why the construction of the Brep then resulted in 5 edges instead of 6 based on that information (I don’t know how much information is “stored” when creating a planar surface about the input polyline). So the initial workaround is just to adjust the polyline so it only is composed of the 4 corner points, which gives me the desired number of brep edges (4).
