Identifying straight cylindrical polysurfaces

Hi guys,

In the attached file I’ve got a bunch of straight and curved tubular surface (that I didn’t make and are often broken into more surfaces than makes any sense) and I’m trying to identify and distinguish the straight from the curved ones. I don’t know if the problem is a bug in my logic or something is returning results I don’t expect, but my code is not working at all. I’m using brep.IsCylinder and .IsPlanar to identify them–if any surface is not cylindrical OR planar, it’s a curved pipe, is that the wrong approach?

Itentifying polysurfaces.3dm (464.0 KB)

Something like this help?
(one edit - otherwise all-planar-faces objects would have been selected as well)

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def TestForStraightCylinders():
    obj_ids=rs.GetObjects("Select objects to check",8+16,preselect=True)
    if not obj_ids: return
    
    rs.UnselectAllObjects()
    tol=sc.doc.ModelAbsoluteTolerance
    to_sel=[]
    for obj_id in obj_ids:
        good=True
        cyl_faces=0
        brep=rs.coercebrep(obj_id)
        for face in brep.Faces:
            if not face.IsCylinder(tol) and not face.IsPlanar(tol):
                good=False
                break
            if face.IsCylinder(tol): cyl_faces+=1
        if good and cyl_faces>0: to_sel.append(obj_id)
    if to_sel: rs.SelectObjects(to_sel)
TestForStraightCylinders()

Thanks, that’s basically what I was trying to do but something was screwy…and I learned that by casting to Brep and looking at Faces I don’t have to handle surfaces and polysurfaces separately…duh!

Yep, a single surface ends up being a one-face brep. Handy.