Create the model with this Python 2 script.
import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
import scriptcontext as sc
def main():
points = rs.coerce3dpointlist((
( 0.0, 0.0, 0.0),
( 0.0, 5.0, 0.0),
( 0.0, 10.0, 0.0),
( 5.0, 0.0, 0.0),
( 5.0, 5.0, 10.0),
( 5.0, 10.0, 0.0),
(10.0, 0.0, 0.0),
(10.0, 5.0, 0.0),
(10.0, 10.0, 0.0),
))
ns = rg.NurbsSurface.CreateFromPoints(
points,
uCount=3,
vCount=3,
uDegree=2,
vDegree=2)
brep = ns.ToBrep()
breps = []
for i in range(100):
for j in range(100):
brep_Trans = brep.DuplicateBrep()
brep_Trans.Translate(rg.Vector3d(10.0*i, 10.0*j, 0.0))
breps.append(brep_Trans)
brep_Joined = rg.Brep.JoinBreps(breps, tolerance=2*sc.doc.ModelAbsoluteTolerance)[0]
sc.doc.Objects.AddBrep(brep_Joined)
sc.doc.Views.RedrawEnabled = False
rs.AddCylinder((5,5,0), height=10, radius=2, cap=True)
sc.doc.Views.RedrawEnabled = True
if __name__ == '__main__': main()
Test the model with this Python 2 script.
from future import absolute_import, division, print_function, unicode_literals
import Rhino
import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
import scriptcontext as sc
from System.Diagnostics import Stopwatch
def main():
gA = rs.GetObject("Select brep A", filter=rs.filter.polysurface, preselect=True)
if gA is None: return
gB = rs.GetObject("Select brep B", filter=rs.filter.polysurface)
if gB is None: return
rgA_In = rs.coercebrep(gA)
rgB_In = rs.coercebrep(gB)
Rhino.RhinoApp.SetCommandPrompt("Working ...")
sw = Stopwatch()
sMethods = (
"rg.Brep.CreateBooleanUnion([rgA_In, rgB_In], tolerance=2.0*sc.doc.ModelAbsoluteTolerance)",
"rg.Brep.CreateBooleanDifference(rgA_In, rgB_In, tolerance=2.0*sc.doc.ModelAbsoluteTolerance)",
"rg.Brep.CreateBooleanIntersection(rgA_In, rgB_In, tolerance=2.0*sc.doc.ModelAbsoluteTolerance)",
)
for sMethod in sMethods:
sw.Restart()
rgB_Res = eval(sMethod)
sw.Stop()
print("{} ms for {}".format(sw.ElapsedMilliseconds, sMethod.split('(')[0]))
if rgB_Res is None:
print("{} failed.".format(sMethod.split('(')[0]))
if name == ‘main’: main()
Picking the larger brep for brep A and the cylinder for brep B, I get these results:
8.8.24163.12481, 2024-06-11
2951 ms for rg.Brep.CreateBooleanUnion
2999 ms for rg.Brep.CreateBooleanDifference
260 ms for rg.Brep.CreateBooleanIntersection
7.37.24107.15001, 2024-04-16
215 ms for rg.Brep.CreateBooleanUnion
2835 ms for rg.Brep.CreateBooleanDifference
247 ms for rg.Brep.CreateBooleanIntersection
Picking the breps in reverse (cylinder then other):
8.8.24163.12481, 2024-06-11
2981 ms for rg.Brep.CreateBooleanUnion
216 ms for rg.Brep.CreateBooleanDifference
214 ms for rg.Brep.CreateBooleanIntersection
7.37.24107.15001, 2024-04-16
233 ms for rg.Brep.CreateBooleanUnion
505 ms for rg.Brep.CreateBooleanDifference
214 ms for rg.Brep.CreateBooleanIntersection
I didn’t include them in the test, but the UI commands, _BooleanUnion, _BooleanDifference, and _BooleanIntersection, all execute in significantly less times in both V7 and V8.