def glue_solids_edges(event=None): # With common edges S3 = BRepPrimAPI_MakeBox(500.,400.,300.).Shape() S4 = BRepPrimAPI_MakeBox(gp_Pnt(0.,0.,300.),gp_Pnt(200.,200.,500.)).Shape() ex3, ex4 = TopExp_Explorer(S3, TopAbs_FACE), TopExp_Explorer(S4, TopAbs_FACE) for a in range(5): ex3.Next() for b in range(4): ex4.Next() F3, F4 = TopoDS.TopoDS_face(ex3.Current()), TopoDS.TopoDS_face(ex4.Current()) glue2 = BRepFeat_Gluer(S4,S3) glue2.Bind(F4,F3) common_edges = LocOpe_FindEdges(F4,F3) common_edges.InitIterator() print 'loop common edges', common_edges.More() while common_edges.More(): print 'common edges',common_edges.EdgeFrom(),common_edges.EdgeTo() glue2.Bind(common_edges.EdgeFrom(),common_edges.EdgeTo()) common_edges.Next() display.EraseAll() glue2.Build() display.DisplayShape(glue2.Shape())
def split_shape(event=None): S = BRepPrimAPI_MakeBox(gp_Pnt(-100,-60,-80),150,200,170).Shape() asect = BRepAlgoAPI_Section(S, gp_Pln(1,2,1,-15),False) asect.ComputePCurveOn1(True) asect.Approximation(True) asect.Build() R = asect.Shape() asplit = BRepFeat_SplitShape(S) for edg in Topo(R).edges(): face = TopoDS.TopoDS_face(TopoDS.TopoDS_Shape()) if asect.HasAncestorFaceOn1(edg, face): asplit.Add(edg, face) asplit.Build() display.EraseAll() display.DisplayShape(asplit.Shape())
def extrusion(event=None): # # Make a box # Box = BRepPrimAPI_MakeBox(400.,250.,300.) S = Box.Shape() # # Choose the first Face of the box # Ex = TopExp_Explorer() Ex.Init(S,TopAbs_FACE) Ex.Next() F = TopoDS.TopoDS_face(Ex.Current()) surf = BRep_Tool_Surface(F) # # Make a plane from this face # Pl = Handle_Geom_Plane_DownCast(surf) Pln = Pl.GetObject() # # Get the normal of this plane. This will be the direction of extrusion. # D = Pln.Axis().Direction() # # Inverse normal # D.Reverse() # # Create the 2D planar sketch # MW = BRepBuilderAPI_MakeWire() p1 = gp_Pnt2d(200.,-100.) p2 = gp_Pnt2d(100.,-100.) aline = GCE2d_MakeLine(p1,p2).Value() Edge1 = BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)) MW.Add(Edge1.Edge()) p1 = p2 p2 = gp_Pnt2d(100.,-200.) aline = GCE2d_MakeLine(p1,p2).Value() Edge2 = BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)) MW.Add(Edge2.Edge()) p1 = p2 p2 = gp_Pnt2d(200.,-200.) aline = GCE2d_MakeLine(p1,p2).Value() Edge3 = BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)) MW.Add(Edge3.Edge()) p1 = p2 p2 = gp_Pnt2d(200.,-100.) aline = GCE2d_MakeLine(p1,p2).Value() Edge4 = BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)) MW.Add(Edge4.Edge()) # # Build Face from Wire. NB: a face is required to generate a solid. # MKF = BRepBuilderAPI_MakeFace() MKF.Init(surf,False, 1e-6) MKF.Add(MW.Wire()) FP = MKF.Face() BRepLib_BuildCurves3d(FP) MKP = BRepFeat_MakePrism(S,FP,F,D,0,True) MKP.Perform(200.) res1 = MKP.Shape() display.EraseAll() display.DisplayColoredShape(res1,'BLUE')