Cut object by plane

I have an ObjRef from GetObject.

Now I want to split this object in 3 parts by dividing with to planes . Is there a way to do this?

Basically I would like to have a version of https://developer.rhino3d.com/5/api/RhinoCommonWin/html/M_Rhino_Geometry_Brep_CreateContourCurves.htm where I just get an array of objects back, divided along the conture lines.

EDIT:
Ok, I tried some things.
The most promising lead was this post by Dale RhinoCommon Brep split by plane
I did like it was written there, I get a PlanarSurface, when I draw it, it is straight throug my object etc. But Brep.Split simply continues returning 0 objects. This is slowly a bit unnerving.

Effectively, I just need the functionality of the BooleanSplit Comman in the Interface. I also tried RunScrip to use the BooleanSplit directly, but it also just returnes with false…

In pseudocode, I would do something like this:

List<ObjRef> SplitByPlanes(ObjRef obj, List<Plane> cutters) {
--
--var splitObjs = new List<obj> {obj};
--
--foreach (Plane cutter in cutters) {
----
----var objCache = new List<obj>();
----
----foreach (ObjRef obj in splitObjs) {
------
------objCache.Add(SplitByPlane(obj, cutter));
----}
----
----splitObjs = objCache;
--}
--
--return splitObjs;
}

List<ObjRef> SplitByPlane(ObjRef obj, Plane cutter) {
--return obj.Split(obj, cutter);
}

Hi Chuck,

thank you for your answer.

The generall setup is clear to me - what I need is the function to perform the actuall splitting, in your code the

As far as I can see, the ObjRef Class does not offer a function “Split” (https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_DocObjects_ObjRef.htm)

I can only find a split method for Breps (https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Brep_Split.htm), but this also requires an Brep as cutter, and planes cannot be converted to Breps.
I think I could somehow piece together a way to represent my plane as Brep, but it seems like an unnecessary detour to me. Thus I was wondering if there is a more direct way.

Ok, I tried some things.
The most promising lead was this post by Dale RhinoCommon Brep split by plane
I did like it was written there, I get a PlanarSurface, when I draw it, it is straight throug my object etc. But Brep.Split simply continues returning 0 objects. This is slowly a bit unnerving.

Effectively, I just need the functionality of the BooleanSplit Comman in the Interface. I also tried RunScrip to use the BooleanSplit directly, but it also just returnes with false…

My bad, obj.Split was a bit of a hand-wave because I wasn’t sure either, misunderstood.

Do you have a copy of the brep and plane returning nothing that you can upload? Dale’s example looks like it should work pretty reliably.

Also, a few alternatives to test (that are actually real, but maybe not as efficient):

brep.Trim(plane, tolerance) result is one contour
plane.Flip()
brep.Trim(plane, tolerance) result is next brep to trim

or

Geometry.Intersect.Intersection.BrepPlane(brep, plane, tolerance, out crv, out pt)
var splitter = Brep.CreatePlanarBrep(crv)
Brep.Split(splitter)

Ok, I am now just converting everything to a Mesh (object and splitting plane) and can then do Mesh.CreateBooleanSplit

This works, but having to convert everything is somewhat cumbersome. There really should be a Split(Obj, Plane) Method…