Delete All Breps that are below a surface level

Hi All,

I m trying to figure out how to manage and delete the surfaces that are under a plane

So far i have managed to do with a constant height but comparing the Z value of the Area Centroid with a specific Z - value
However I dont know how to modify the script that it finds the corresponding Z value of the plane

To illustrate:
I have this plane which is actually an extruded polyline
image

The forward part has a Z = 1300 so with the script below all forward part that is below 1300 are removed

import rhinoscriptsyntax as rs

def extrude_crv(B):
    # Select Curve
    crv = rs.GetObject("Select Curve to Extrude")
    rs.EnableRedraw(False)
    # Extrude Curve
    start_point = rs.CurveStartPoint(crv)
    end_point = start_point + rs.coerce3dpoint((0,B,0))
    path = rs.AddLine(start_point,end_point)
    extruded_plane = rs.ExtrudeCurve(crv, path)
    return extruded_plane


B=10000 
x_min = 0
x_max = 100000
length = 1000

y_min = 0
breadth = 5000

z_min = 0
height = 15000


breps = []
extrude_plane = extrude_crv(B)


for x in range(x_min,x_max,1000):
    rectangle = rs.AddRectangle( rs.WorldYZPlane(), breadth, height)
    obj = rs.MoveObject(rectangle, (x, y_min, z_min) )
    obj = rs.AddPlanarSrf(obj)
    rs.DeleteObject(rectangle)
    breps.append(obj)



for brep in breps:
    if rs.IsSurface(brep):
        splits = rs.SplitBrep ( brep, extrude_plane )
        if splits:
            for obj in splits:
                if obj:
                    cog = rs.SurfaceAreaCentroid(obj)
                    if cog[0].Z < 1300:
                        rs.DeleteObject(obj)
                    rs.DeleteObject(brep)

Any ideas on how to approach this would be really helpful!

For convenience i also attach the rhinofile with the polyline
split_brep.3dm (27.3 KB)

That’s nice, but your file does only contain a curve, nothing else. :slight_smile:

Indeed!
Try to run the scirpt and select the line
I provided the file in order to avoid crashes as the script is not cathcing any error yet.

Btw i solved this this morning by checking the intersection

def TrimBelowSurface(obj_ids, extrude_plane):
    for brep in obj_ids:
        if rs.IsSurface(brep):
            intersection = rs.IntersectBreps(brep, extrude_plane)
            if intersection:
                if rs.IsCurve(intersection):
                    local_plane_height = rs.CurveStartPoint(intersection)
            else:
                local_plane_height = rs.BoundingBox(extrude_plane)
                min_height = 10**6
                for i in range(4):
                    min_height_tmp = local_plane_height[i].Z
                    if min_height_tmp < min_height:
                        min_height = min_height_tmp
            splits = rs.SplitBrep ( brep, extrude_plane )
            if splits:
                for obj in splits:
                    if obj:
                        cog = rs.SurfaceAreaCentroid(obj)
                        if cog[0].Z < local_plane_height.Z:
                            rs.DeleteObject(obj)
                        rs.DeleteObject(brep)

Sounds great!