How to selected the top surface in polysurface

I have multi object are polysurface type. I want select the top surface in polysurface.

One method may be to compare a face normal to +z axis:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino


guids = rs.GetObjects('select objects')
up = Rhino.Geometry.Vector3d.ZAxis
for guid in guids:
    brep = rs.coercebrep(guid)
    robj = rs.coercerhinoobject(guid)
    for face in brep.Faces:
        # Use top-center bounding box point to sample face
        bbox = face.GetBoundingBox(Rhino.Geometry.Plane.WorldXY)
        top_point = bbox.PointAt(0.5, 0.5, 1)
        # Find closest u,v point to top-center
        closest_point_ok, u, v = face.ClosestPoint(top_point)
        # Find face normal at closest point u,v coords
        normal = face.NormalAt(u, v)
        # Calc angle between up and normal vector
        angle = Rhino.Geometry.Vector3d.VectorAngle(up, normal)
        degrees = Rhino.RhinoMath.ToDegrees(angle)
        # If angle is less than some threshold, select it
        if degrees < 45:
            robj.SelectSubObject(face.ComponentIndex(), True, True, True)

Another method may be to use the bounding box center for each face and select the highest one.

Guess it will depend on how ‘normal’ your polysurfaces are to the example file.

3 Likes

it’s working. Thank you @nathancoatney