Subtracting areas from surface - python

Hi all,

I am trying to solve the problem below via a python script. I have a lot (600+) of these situation where I have as input surfaces and I would have to remove areas from these surfaces:

However I can’t find an easy way to do it via scripting, making the red contours solids and then booleaning them out of the initial surface seems to fail, also I would need to do this on a lot of elements, anyone could suggest a smart way to do it?

e.g. script not working and potentially too slow:

import rhinoscriptsyntax as rs

surface = rs.GetObject("srf", 8)
cutpieces = rs.GetObjects("curves")
path = rs.AddLine([0,0,0],[3,0,0])
solids = []

for cutpiece in cutpieces:
    newsolid = rs.ExtrudeCurve(cutpiece, path)
    rs.MoveObject(newsolid, [-1.5,0,0])

Many thanks in advance

removing areas.3dm (77.1 KB)

don’t know python but very easy with grasshopper:

Kind regards Ferry

Hi revink
You can try this code.I also recommend using Grasshopper. If you must run it in Rhino, you can also use the GrasshopperPlayer command (rhino7.0) to run the GH file.

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
import scriptcontext as sc
import Rhino.RhinoDoc as rr

tol = rr.ActiveDoc.ModelAbsoluteTolerance

surface = rs.GetObject("srf", rs.filter.surface)
if surface:
    curves = rs.GetObjects("curves",rs.filter.curve)
    if curves:
        surface_geo =  rs.coercebrep(surface)
        curves_geos = [rs.coercecurve(guid) for guid in curves]
        bool_curves = rg.Curve.CreateBooleanUnion(curves_geos)
        if (bool_curves and surface_geo):
            bool_breps2 = rg.Brep.CreatePlanarBreps(bool_curves)
            brep3 = rg.Brep.CreateBooleanDifference([surface_geo],bool_breps2,tol)
            if brep3:
                for brep in brep3:

Thanks Naruto, this seems to work great. Do you think it can be tweaked to subtract areas from a mesh as well? I can’t seem to make it work (but not very good with rhino common)

Thanks again