def make_wire(*args): # if we get an iterable, than add all edges to wire builder if isinstance(args[0], list) or isinstance(args[0], tuple): wire = BRepBuilderAPI_MakeWire() for i in args[0]: wire.Add(i) wire.Build() return wire.Wire() wire = BRepBuilderAPI_MakeWire(*args) wire.Build() with assert_isdone(wire, 'failed to produce wire'): result = wire.Wire() return result
def make_wire(*args): # if we get an iterable, than add all edges to wire builder if isinstance(args[0], list) or isinstance(args[0], tuple): wire = BRepBuilderAPI_MakeWire() for i in args[0]: wire.Add(i) wire.Build() return wire.Wire() wire = BRepBuilderAPI_MakeWire(*args) return wire.Wire()
def make_wire(*args): # if we get an iterable, than add all edges to wire builder if isinstance(args[0], (list, tuple)): wire = BRepBuilderAPI_MakeWire() for i in args[0]: wire.Add(i) wire.Build() return wire.Wire() wire = BRepBuilderAPI_MakeWire(*args) assert_isdone(wire, "failed to produce wire") return wire.Wire()
def make_wire(edges, fillets=None): # the wire # print("adding wire") makeWire = BRepBuilderAPI_MakeWire() makeWire.Add(edges[0]) if fillets is None: for edge in edges[1:]: makeWire.Add(edge) else: for fillet, edge in zip(fillets, edges[1:]): makeWire.Add(fillet) makeWire.Add(edge) # print("build wire") makeWire.Build() # print("make wire") wire = makeWire.Wire() return wire
def make_wire(edges, fillets=None): # the wire # print("adding wire") makeWire = BRepBuilderAPI_MakeWire() makeWire.Add(edges[0]) if fillets is None: for edge in edges[1:]: makeWire.Add(edge) else: for fillet, edge in zip(fillets, edges[1:]): makeWire.Add(fillet) makeWire.Add(edge) # print("build wire") makeWire.Build() # print("make wire") try: wire = makeWire.Wire() except RuntimeError as e: print(type(makeWire)) raise e return wire
def brepfeat_prism(event=None): box = BRepPrimAPI_MakeBox(400, 250, 300).Shape() faces = TopologyExplorer(box).faces() for i in range(5): face = next(faces) srf = BRep_Tool_Surface(face) c = gp_Circ2d(gp_Ax2d(gp_Pnt2d(200, 130), gp_Dir2d(1, 0)), 75) circle = Geom2d_Circle(c) wire = BRepBuilderAPI_MakeWire() wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, 0., pi).Edge()) wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, pi, 2. * pi).Edge()) wire.Build() display.DisplayShape(wire.Wire()) mkf = BRepBuilderAPI_MakeFace() mkf.Init(srf, False, 1e-6) mkf.Add(wire.Wire()) mkf.Build() new_face = mkf.Face() breplib_BuildCurves3d(new_face) display.DisplayShape(new_face) prism = BRepFeat_MakeDPrism(box, mkf.Face(), face, 100, True, True) prism.Perform(400) assert prism.IsDone() display.EraseAll() display.DisplayShape(prism.Shape()) display.DisplayColoredShape(wire.Wire(), 'RED') display.FitAll()
def sweep_pipe(edge, xvec, r, wt, geom_repr=ElemType.SOLID): if geom_repr not in [ElemType.SOLID, ElemType.SHELL]: raise ValueError("Sweeping pipe must be either 'solid' or 'shell'") t = TopologyExplorer(edge) points = [v for v in t.vertices()] point = BRep_Tool_Pnt(points[0]) # x, y, z = point.X(), point.Y(), point.Z() direction = gp_Dir(*unit_vector(xvec).astype(float).tolist()) # pipe makeWire = BRepBuilderAPI_MakeWire() makeWire.Add(edge) makeWire.Build() wire = makeWire.Wire() try: if geom_repr == ElemType.SOLID: i = make_circular_sec_face(point, direction, r - wt) elbow_i = BRepOffsetAPI_MakePipe(wire, i).Shape() o = make_circular_sec_face(point, direction, r) elbow_o = BRepOffsetAPI_MakePipe(wire, o).Shape() else: elbow_i = None o = make_circular_sec_wire(point, direction, r) elbow_o = BRepOffsetAPI_MakePipe(wire, o).Shape() except RuntimeError as e: logging.error(f'Pipe sweep failed: "{e}"') return wire if geom_repr == ElemType.SOLID: boolean_result = BRepAlgoAPI_Cut(elbow_o, elbow_i).Shape() if boolean_result.IsNull(): logging.debug("Boolean returns None") else: boolean_result = elbow_o return boolean_result