Cutting an object with multiple objects - rhinoscriptsyntax

Hi all,

I am trying to do what would seem a very simple operation with python but it appears to be more difficult than expected. I have a surface (or multiple surfaces) I have to split with a list of cubes, then I have to assign each of these surfaces to a layer and split them in turn with a list of lines. (see attached image)

However the rhinoscriptsyntax doesn’t allow for this as it requires to use just to object at the time. I thought I could then use the rs.command but however I can’t manage to select the objects I want to cut my surface with. Below the code I am using

import rhinoscriptsyntax as rs

srf = rs.GetObject("surface to cut",8)
cuttingObjects = rs.GetObjects("cutting elements",16)

rs.SelectObject(srf)
rs.Command("split ")
rs.SelectObjects(cuttingObjects)
rs.Command(" ")
rs.UnselectAllObjects()

I tried for example to move the objects I want to cut my surface with and then write “sellast” in the command string, however this doesn’t appear to work.

Any way this could be solved?

Thanks in advance

Hello - the usual way to provide selections to rs.Command() would be to build the command string using "SelId " + str(id)
that is using a string representing the ids of the objects.

But, you should be able to get there without resorting to rs.Command(), if you delve into RhinoCommon

https://developer.rhino3d.com/api/RhinoCommon/html/Overload_Rhino_Geometry_Brep_Split.htm

which really is the way to go for this, I would say.

-Pascal

Thanks Pascal,

Agree rs.command not really solid. Could you help me with the rhinocommon syntax? I am trying the following below but I get this error message

Message: Multiple targets could match: Split(IEnumerable[Curve], float), Split(IEnumerable[Brep], float), Split(Brep, float), Split(Brep, float)

How should I amend it?

> import rhinoscriptsyntax as rs
import Rhino

srf = rs.GetObject("surface to cut",8)
cuttingObjects = rs.GetObjects("cutting elements",16)

surface = rs.coercebrep(srf)
objs = rs.coercebrep(cuttingObjects)
surface.Split(objs, 0.01)

Hello - something like this I’d say - you need to make it a list of the cutters.

import scriptcontext as sc #<<<< at the top of your script if it is no there
tol = .001
SRF = rs.coercebrep(srf)
breps= [rs.coercebrep(id) for id in cuttingObjects]
splitList = SRF.Split(breps, tol)

newIds = [ sc.doc.Objects.AddBrep(brep) for brep in splitList]

The above not tested…

OK. yeahhh… that ‘Multiple targets’ thing is back… let me think…

I am shifting this over to the Scripting forum though… let’s continue there.

@revink - it gets a little weird in this particular case (Multiple targets could match) That refers to the function being able to take breps OR curves as input for the cutters and in Python it cannot tell what you’re handing it so you need to be more explicit. Admittedly this is not an ideal example to get started with RhinoCommon - the relevant info is here in a post from @dale -

and here is an example for your case:

import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs
import System.Collections.Generic.IEnumerable as IEnumerable
import System.Double as sd
   
       
tol = .001
srf = rs.GetObject(filter=8)
SRF = rs.coercebrep(srf)
cuttingObjects = rs.GetObjects(filter= 8 + 16)
breps= [rs.coercebrep(id) for id in cuttingObjects]

splitList = SRF.Split.Overloads[IEnumerable[Rhino.Geometry.Brep], sd]( breps, tol) #<<<Here

newIds = [ sc.doc.Objects.AddBrep(brep) for brep in splitList]

As you can see, I am first telling brep.Split exactly what it is I am about to give it (breps and a double, not curves and a double ) and then I give the inputs. This is not usually needed… but you hit a tricky one.

-Pascal

Thanks Pascal, this works perfectly for surfaces, now in my second step I was trying to cut each surface with curves, however the below seems not to work (I don’t get any split geometry). Any idea on how to amend?

    surface = rs.GetObject("Surface",8)
    tol = .0001
    SRF = rs.coercebrep(surface)
    
    
    cuttingObjects = rs.GetObjects("crvs",4)
    curves = [rs.coercecurve(id) for id in cuttingObjects]

    if SRF:
        splitList = SRF.Split.Overloads[IEnumerable[Rhino.Geometry.Curve], sd]( curves, tol)
        newIds = [ sc.doc.Objects.AddBrep(brep) for brep in splitList]