Hi Charles, I made a rudimentary fix of your script. The memory magic ( I got 8GB and am feeling lucky ;) is most likely due to the boolean_fuse function using the .Destroy method ) def boolean_fuse(shapeToCutFrom, joiningShape): from OCC.BRepAlgoAPI import BRepAlgoAPI_Fuse join = BRepAlgoAPI_Fuse(shapeToCutFrom, joiningShape) join.RefineEdges() join.FuseEdges() shape = join.Shape() join.Destroy() return shape I strongly encourage you to use the functions found in OCC.Utils.Construct! This makes the program dramtatically less verbose and provides a more polished API ( and cleans up after you, raises exceptions with informative messages, all that good stuff ) This should be able to build your geometry, perhaps you need a 64 bit binary, but perhaps not… However, the *only* right way to do this, is to build the geometry you want to subtract as a compound, as Fotios pointed out. Recently, we fixes a minor issue that prevented this pattern: BRep_Builder B; TopoDS_Compound C; B.MakeCompound(C); for (ind = 1; ind <= nbshapes; ind++) { B.Add(C, aShape_i); } aCompoundShape = C; This works in SVN, so perhaps an interesting exercise to implement the correct version? It will be infinitely faster and more stable than this approach, but hey, what ever works. Oh, and pay attention to the ipd.set_trace() trick. It will show your geometry in the GUI as it continues to build. Note that the viewer is interactive. Makes life much easier. Best, -jelle |
from OCC.BRepPrimAPI import * import OCC.gp import OCC.GC import OCC.BRepBuilderAPI import OCC.Geom import OCC.BRepPrimAPI import OCC.BRepAlgoAPI import OCC.Utils.DataExchange.STEP import OCC.Utils.DataExchange.STL import OCC.TopoDS import OCC.BRep import OCC.GarbageCollector import numpy as NP import math import multiprocessing as processing
gc = OCC.GarbageCollector.GarbageCollector() # pythonic from OCC.Utils.Construct import * # GUI from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_function_to_menu = init_display() length = 594.6 width = 136.0 thickness = 5.0 spacing = 2.1 groove_width = 0.175 groove_depth = 0.03 number_of_slices = int(math.floor(length/spacing)) box = BRepPrimAPI_MakeBox(spacing,width,thickness).Shape() # Make the transverse groove print('Adding transverse groove') pnt1 = OCC.gp.gp_Pnt(spacing/2.0, 0., thickness - groove_depth) pnt2 = OCC.gp.gp_Pnt(spacing/2.0 + groove_width/2.0, 0., thickness) pnt3 = OCC.gp.gp_Pnt(spacing/2.0 - groove_width/2.0, 0., thickness) e1 = make_edge(pnt1, pnt2) e2 = make_edge(pnt2, pnt3) e3 = make_edge(pnt3, pnt1) face = make_face(make_wire([e1,e2,e3])) v = OCC.gp.gp_Vec(0., width, 0.) b = make_prism(face , v) print('Making transverse cut') lga = boolean_cut(box, b) # Make the grooves with an arithmetic progression a1 = 1.32 # Spacing between first two grooves an = 0.85 # Spacing between next to the last and the last groove d1 = 9.0 # Distance from the edge to the center of the first groove d2 = 9.0 # Distance from the edge to the center of the last groove sn = width - d1 - d2 # Distance from first groove to last groove n = int(math.floor(2*sn/(a1+an))) # number of grooves d = (an-a1)/(n-1) # difference in spacing between grooves y = d1 print('number of grooves %d' % (n,)) for i, k in enumerate(range(40)): #for i, k in enumerate(range(1,n+1)): print('Adding longitudinal groove %d of %d' % (i+1, n)) print('y %s' % (y,)) pnt1 = OCC.gp.gp_Pnt(0.0, y, thickness - groove_depth) pnt2 = OCC.gp.gp_Pnt(0.0, y + groove_width/2.0, thickness) pnt3 = OCC.gp.gp_Pnt(0.0, y - groove_width/2.0, thickness) e1 = make_edge(pnt1, pnt2) e2 = make_edge(pnt2, pnt3) e3 = make_edge(pnt3, pnt1) face = make_face(make_wire([e1,e2,e3])) v = OCC.gp.gp_Vec(spacing, 0., 0.) b = make_prism(face , v) ak = a1 + (k-1)*d y = y + ak print('Making longitudinal cut') lga = boolean_cut(lga, b) # Transform the slices slices = [lga,] v = OCC.gp.gp_Vec(spacing, 0., 0.) display.DisplayShape(lga) # merge this into a compound... print 'n slices', number_of_slices for i in range(1, 40): #for i in range(1, number_of_slices): print('Translating %s' % (i,)) #trans = OCC.gp.gp_Trsf() #trans.SetTranslation(v) brep_trns = translate_topods_from_vector(slices[i - 1], v, True) slices.append(brep_trns) lga = boolean_fuse(lga, brep_trns) import ipdb; ipdb.set_trace() display.EraseAll() display.DisplayShape(lga) def fuse(shapes): a = shapes[0][1] b = shapes[1][1] return boolean_fuse(a,b) #P = processing.Pool(7) ## each member of results is initially a tuple of the index and the shape #results = [(i,a) for i, a in enumerate(slices[:24])] #while len(results) > 1: # if len(results) % 2 != 0: # ''' # Replace the last two elements of the list with the fuse of the two # ''' # a = results[-2] # b = results[-1] # del results[-2:] # results.append(fuser((a,b))) # results = P.map(fuse, [(a,b) for a,b in zip(results[::2],results[1::2])]) # ''' # Need to sort since there is no guarantee the results will be returned in order # With each pass through this while loop, the sort key will look like: # Pass 1: 0,1,2,..., potentially (n-1,n) # Pass 2: (0,1), (2,3), (4,5), ... # Pass 3: ((0,1),(2,3)), ((4,5),(6,7)), ... # ''' # results.sort(key=lambda result: result[0]) #P.close() #P.join() #stp_exporter = OCC.Utils.DataExchange.STEP.STEPExporter('lga.stp') start_display() #stp_exporter.SetTolerance(tolerance=0.00001) #stp_exporter.AddShape(lga) #stp_exporter.WriteFile()
_______________________________________________ Pythonocc-users mailing list Pythonocc-users@gna.org https://mail.gna.org/listinfo/pythonocc-users