Count surface edges with Python

Is there a method to count the number of edges in a surface? I would like to find surfaces that are circular, with only a single edge.

Or maybe there is a better way to select surfaces like those shown above? I should mention that there are a number of other operations happening so I would prefer not to prompt the user to pick anything (as with GetEdgeCurves).

Thanks,

Dan

Hi @DanBayn,

below seems to work:

import Rhino
    
def MyFilter(rhObject, geometry, componentIndex):
    if geometry.AdjacentEdges().Count == 1:
        if geometry.AdjacentFaces().Count == 1:
            crv = geometry.OuterLoop.Trims[0].Edge.ToNurbsCurve()
            rc, circle = Rhino.Geometry.Curve.TryGetCircle(crv, 0.001)
            if rc: return True
    return False
    
def DoSomething():
    gs = Rhino.Input.Custom.GetObject()
    gs.SetCommandPrompt("Select surface with circular trim")
    gs.DisablePreSelect()
    gs.SubObjectSelect = True
    gs.DeselectAllBeforePostSelect = True
    gs.GeometryFilter = Rhino.DocObjects.ObjectType.Surface
    gs.SetCustomGeometryFilter(MyFilter)
    get_rc = gs.GetMultiple(1, 0)
    if gs.CommandResult() != Rhino.Commands.Result.Success:
        return gs.CommandResult()
    elif get_rc == Rhino.Input.GetResult.Object:
        for objRef in gs.Objects():
            brep_id = objRef.ObjectId
            face_index = objRef.GeometryComponentIndex.Index
            print "ID: {} >>> Face index: {}".format(brep_id, face_index)
    
DoSomething()

Btw. instead of a getter, you might just iterate over the brep faces and do the same as MyFilter does.

c.

Hi Clement,

I will give this a try first thing in the morning.

Very much appreciated,

Thanks,

Dan