def fillet(event=None): Box = BRepPrimAPI_MakeBox(gp_Pnt(-400, 0, 0), 200, 230, 180).Shape() fillet = BRepFilletAPI_MakeFillet(Box) # Add fillet on each edge for e in Topo(Box).edges(): fillet.Add(20, e) blendedBox = fillet.Shape() P1 = gp_Pnt(250, 150, 75) S1 = BRepPrimAPI_MakeBox(300, 200, 200).Shape() S2 = BRepPrimAPI_MakeBox(P1, 120, 180, 70).Shape() Fuse = BRepAlgoAPI_Fuse(S1, S2) FusedShape = Fuse.Shape() fill = BRepFilletAPI_MakeFillet(FusedShape) for e in Topo(FusedShape).edges(): fill.Add(e) for i in range(1, fill.NbContours() + 1): length = fill.Length(i) Rad = 0.15 * length fill.SetRadius(Rad, i, 1) blendedFusedSolids = fill.Shape() display.EraseAll() display.DisplayShape(blendedBox) display.DisplayShape(blendedFusedSolids) display.FitAll()
def boolean_fuse(shapeToCutFrom, joiningShape): join = BRepAlgoAPI_Fuse(shapeToCutFrom, joiningShape) join.RefineEdges() join.FuseEdges() shape = join.Shape() join.Destroy() return shape
def fuse(self, toFuse): """ Fuse shapes together """ fuse_op = BRepAlgoAPI_Fuse(self.wrapped, toFuse.wrapped) fuse_op.RefineEdges() fuse_op.FuseEdges() # fuse_op.SetFuzzyValue(TOLERANCE) fuse_op.Build() return Shape.cast(fuse_op.Shape())
def brep_feat_extrusion_protrusion(event=None): #Extrusion S = BRepPrimAPI_MakeBox(400.,250.,300.).Shape() faces = Topo(S).faces() F = faces.next() surf1 = BRep_Tool_Surface(F) Pl1 = Handle_Geom_Plane_DownCast(surf1).GetObject() D1 = Pl1.Pln().Axis().Direction().Reversed() MW = BRepBuilderAPI_MakeWire() p1,p2 = gp_Pnt2d(200.,-100.), gp_Pnt2d(100.,-100.) aline = GCE2d_MakeLine(p1,p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline,surf1,0.,p1.Distance(p2)).Edge()) p1,p2 = gp_Pnt2d(100.,-100.), gp_Pnt2d(100.,-200.) aline = GCE2d_MakeLine(p1,p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline,surf1,0.,p1.Distance(p2)).Edge()) p1,p2 = gp_Pnt2d(100.,-200.), gp_Pnt2d(200.,-200.) aline = GCE2d_MakeLine(p1,p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline,surf1,0.,p1.Distance(p2)).Edge()) p1,p2 = gp_Pnt2d(200.,-200.), gp_Pnt2d(200.,-100.) aline = GCE2d_MakeLine(p1,p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline,surf1,0.,p1.Distance(p2)).Edge()) MKF = BRepBuilderAPI_MakeFace() MKF.Init(surf1,False,1e-6) MKF.Add(MW.Wire()) FP = MKF.Face() BRepLib_BuildCurves3d(FP) # MKP = BRepFeat_MakePrism(S,FP,F,D1,0,True) # MKP.Perform(-200) # print 'depth 200' # res1 = MKP.Shape() # display.DisplayShape(res1) # time.sleep(1) display.EraseAll() MKP = BRepFeat_MakePrism(S,FP,F,D1,0,True) MKP.PerformThruAll() print 'depth thru all' res1 = MKP.Shape() # display.DisplayShape(res1) # Protrusion faces.next() F2 = faces.next() surf2 = BRep_Tool_Surface(F2) Pl2 = Handle_Geom_Plane_DownCast(surf2).GetObject() D2 = Pl2.Pln().Axis().Direction().Reversed() MW2 = BRepBuilderAPI_MakeWire() p1, p2 = gp_Pnt2d(100.,100.), gp_Pnt2d(200.,100.) # p1, p2 = gp_Pnt2d(100.,100.), gp_Pnt2d(150.,100.) aline = GCE2d_MakeLine(p1,p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf2,0.,p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(200.,100.), gp_Pnt2d(150.,200.) aline = GCE2d_MakeLine(p1,p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf2,0.,p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(150.,200.), gp_Pnt2d(100.,100.) aline = GCE2d_MakeLine(p1,p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf2,0.,p1.Distance(p2)).Edge()) MKF2 = BRepBuilderAPI_MakeFace() MKF2.Init(surf2,False,1e-6) MKF2.Add(MW2.Wire()) MKF2.Build() # display.DisplayShape(MW2.Wire()) FP = MKF2.Face() BRepLib_BuildCurves3d(FP) MKP2 = BRepFeat_MakePrism(res1,FP,F2,D2,0,True) MKP2.PerformThruAll() display.EraseAll() # display.DisplayShape(MKP2.Shape()) trf = gp_Trsf() trf.SetTranslation(gp_Vec(0,0,300)) gtrf = gp_GTrsf() gtrf.SetTrsf(trf) tr = BRepBuilderAPI_GTransform(MKP2.Shape(), gtrf, True) from OCC.BRepAlgoAPI import BRepAlgoAPI_Fuse fused = BRepAlgoAPI_Fuse(tr.Shape(), MKP2.Shape()) fused.RefineEdges() fused.Build() print 'boolean operation error status:', fused.ErrorStatus() display.DisplayShape(fused.Shape())
def char_to_solid(self, glyph): layer = glyph.layers['Fore'] bodies = [] for contour in layer: i = 0 total = len(contour) curve_points = [] if total <= 2: # Can't make solid out of 1 or 2 points continue wire = BRepBuilderAPI_MakeWire() for point in contour: if point.on_curve: if i > 0: # Complete old curve curve_points.append(gp_Pnt(point.x, point.y, 0)) self.add_to_wire(curve_points, wire) if i < total: # Start new curve curve_points = [gp_Pnt(point.x, point.y, 0)] if i == total-1: first = contour[0] curve_points.append(gp_Pnt(first.x, first.y, 0)) self.add_to_wire(curve_points, wire) else: curve_points.append(gp_Pnt(point.x, point.y, 0)) if i == total-1: first = contour[0] curve_points.append(gp_Pnt(first.x, first.y, 0)) self.add_to_wire(curve_points, wire) i += 1 face = BRepBuilderAPI_MakeFace(wire.Wire()) extrusion_vector = gp_Vec(0, 0, self.thickness) prism = BRepPrimAPI_MakePrism(face.Shape(), extrusion_vector) bodies.append(dict( prism = prism, isClockwise = contour.isClockwise(), )) if len(bodies) > 0: if len(bodies) == 1: return bodies[0]['prism'].Shape() elif len(bodies) > 1: final = None positive_union = None for body in bodies: if body['isClockwise'] == 1: if positive_union: positive_union = BRepAlgoAPI_Fuse( positive_union.Shape(), body['prism'].Shape()) else: positive_union = body['prism'] negative_union = None for body in bodies: if body['isClockwise'] == 0: if negative_union: negative_union = BRepAlgoAPI_Fuse( negative_union.Shape(), body['prism'].Shape()) else: negative_union = body['prism'] if positive_union and negative_union: final = BRepAlgoAPI_Cut( positive_union.Shape(), negative_union.Shape()) elif positive_union: final = positive_union elif negative_union: final = negative_union return final.Shape()