Brep for Planar Rectangular Surface returns 5 edges

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)?

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))

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:

        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

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).