def extrusion(event=None): # Make a box Box = BRepPrimAPI_MakeBox(400., 250., 300.) S = Box.Shape() # Choose the first Face of the box F = next(Topo(S).faces()) 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, False, True) MKP.Perform(200.) # TODO MKP completes, seeing a split operation but no extrusion assert MKP.IsDone() res1 = MKP.Shape() display.EraseAll() display.DisplayColoredShape(res1, 'BLUE') display.DisplayColoredShape(FP, 'YELLOW') display.FitAll()
def make_reference(self, **parameters): l = parameters['length'] w = parameters['width'] h = parameters['height'] box_shape = BRepPrimAPI_MakeBox(l, w, h) transform = gp.gp_Trsf() transform.SetTranslation(gp.gp_Vec(-l / 2, -w / 2, -h / 2)) shape_transform = BRepTransform(box_shape.Shape(), transform, False) shape_transform.Build() shape = shape_transform.Shape() return shape
def make_box(*args): p1, p2 = None, None if isinstance(args, (list, tuple)): if len(args) == 2: p1 = make_pnt(args[0]) p2 = make_pnt(args[1]) elif len(args) == 6: p1 = gp_Pnt(*args[0:3]) p2 = gp_Pnt(*args[3:]) if p1 is None: return box = BRepPrimAPI_MakeBox(p1, p2) box.Build() with assert_isdone(box, 'failed to built a cube...'): return box.Shape()
def make_box(*args): box = BRepPrimAPI_MakeBox(*args) box.Build() with assert_isdone(box, 'failed to built a cube...'): return box.Shape()
def _get_viewer(self): return self.canvas._display.GetViewer().GetObject() def _get_context(self): return self.canvas._display.GetContext().GetObject() if __name__ == "__main__": import sys from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox app = QApplication(sys.argv) viewer = OCCViewer() viewer.show_line() dlg = QDialog() dlg.setFixedHeight(400) dlg.setFixedWidth(600) layout(dlg, (viewer, ), dlg) dlg.show() box = BRepPrimAPI_MakeBox(20, 20, 30) box_ais = AIS_ColoredShape(box.Shape()) viewer.display(box_ais) sys.exit(app.exec_())
lim_coord2 = (ymin, ymax) section_height = zmax-1e-3 # A horizontal plane is created from which a face is constructed to intersect with # the building. The face is transparently displayed along with the building. section_plane = gp_Pln( gp_Pnt(0, 0, section_height), gp_Dir(0, 0, 1) ) section_face = BRepBuilderAPI_MakeFace(section_plane, xmin, xmax, ymin, ymax).Face() # Build cut bounding box height = 0.18 p = gp_Pnt(xmin, ymin, zmax-height) selectBox = BRepPrimAPI_MakeBox(p, xmax-xmin, ymax-ymin, -(zmax-zmin-height)) shape2 = BRepAlgoAPI_Cut(shape, selectBox.Shape()).Shape() # ifcopenshell.geom.utils.display_shape(shape) # ifcopenshell.geom.utils.display_shape(selectBox.Shape()) ifcopenshell.geom.utils.display_shape(shape2) plt.figure() plt.xlim(lim_coord1) plt.ylim(lim_coord2) objects = set() # Explore the faces of the shape (these are known to be named) exp = TopExp_Explorer(shape, TopAbs_FACE) while exp.More(): s = exp.Current()