Having a brain block here… I am trying to create a function that splits a brep with any number of curves (that might or might not actually split the brep).
Test file:
Split_Brep_Test.3dm (37.7 KB)
The following fails when selecting the surface and all 4 curves:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino, System
from System.Collections.Generic import IEnumerable
def SplitBrepWCrvs(brepID,crvIDs,tol,del_orig=True):
brep=rs.coercebrep(brepID)
crvs=[rs.coercecurve(crvID) for crvID in crvIDs]
splits=brep.Split.Overloads[IEnumerable[Rhino.Geometry.Curve],System.Double](crvs, tol)
if splits and len(splits)>1:
sc.doc.Objects.Delete(brepID,True)
return [sc.doc.Objects.AddBrep(brep) for brep in splits]
brepID=rs.GetObject("Select brep to split",8+16)
crvIDs=rs.GetObjects("Select splitting curves",4)
result=SplitBrepWCrvs(brepID,crvIDs,sc.doc.ModelAbsoluteTolerance,True)
because of this bug I previously reported, which will not be fixed until V7. Interestingly enough if you use only one of the two green curves and the red one which lies on the surface, it still does not do what it is supposed to do - it also looks like it fails if any curves cross each other. Only the two green ones work together.
So, I thought I’d try to “roll my own” , but I’m still not succeeding completely - I am still not getting all the splits I am supposed to, even though it is better.
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino, System
from System.Collections.Generic import IEnumerable
def SplitBrepWCrvs(brepID,crvIDs,tol,del_orig=True):
orig_brep=rs.coercebrep(brepID)
crvs=[rs.coercecurve(crvID) for crvID in crvIDs]
split_parts=[orig_brep]
for crv in crvs:
for brep in split_parts:
splits=brep.Split.Overloads[IEnumerable[Rhino.Geometry.Curve],System.Double]([crv], tol)
if splits and len(splits)>1:
split_parts.remove(brep)
for split in splits:
split_parts.append(split)
if split_parts:
sc.doc.Objects.Delete(brepID,True)
return [sc.doc.Objects.AddBrep(brep) for brep in split_parts]
brepID=rs.GetObject("Select brep to split",8+16)
crvIDs=rs.GetObjects("Select splitting curves",4)
result=SplitBrepWCrvs(brepID,crvIDs,sc.doc.ModelAbsoluteTolerance,True)
Somehow it seems like this should work, but I’m at a loss as to why it is not 100%. Did I miss something dumb here, or do I need to make an excursion into recursion?
TIA, --Mitch