def _revol(shp, r=None, yaw=0.0): if r is not None: shp = shp.rotX(deg(90)).movX(r) ax = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) if yaw == 0: return Shape(BRepPrimAPI_MakeRevol(shp.Shape(), ax).Shape()) else: return Shape(BRepPrimAPI_MakeRevol(shp.Shape(), ax, yaw).Shape())
def revolve(): """Revolve profile on active WP to create a new part.""" wp = win.activeWp if win.lineEditStack and len(win.ptStack) == 2: p2 = win.ptStack.pop() p1 = win.ptStack.pop() name = win.lineEditStack.pop() win.clearAllStacks() wireOK = wp.makeWire() if not wireOK: print("Unable to make wire.") return face = BRepBuilderAPI_MakeFace(wp.wire).Shape() revolve_axis = gp_Ax1(p1, gp_Dir(gp_Vec(p1, p2))) myBody = BRepPrimAPI_MakeRevol(face, revolve_axis).Shape() uid = doc.addComponent(myBody, name, DEFAULT_COLOR) win.build_tree() win.setActivePart(uid) win.draw_shape(uid) win.syncUncheckedToHideList() win.statusBar().showMessage("New part created.") win.clearCallback() else: win.registerCallback(revolveC) display.SetSelectionModeVertex() win.lineEdit.setFocus() statusText = "Pick two points on revolve axis." win.statusBar().showMessage(statusText)
def make_revolved_cylinder(pnt, height, revolve_angle, rotation, wall_thick): """ This method demonstrates how to create a revolved shape from a drawn closed edge. It currently creates a hollow cylinder adapted from algotopia.com's opencascade_basic tutorial: http://www.algotopia.com/contents/opencascade/opencascade_basic :param pnt: :param height: :param revolve_angle: :param rotation: :param wall_thick: :type pnt: dict :type height: float :type revolve_angle: float :type rotation: float :type wall_thick: float """ from OCC.Core.BRepBuilderAPI import ( BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeFace, BRepBuilderAPI_MakeWire, ) from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeRevol from OCC.Core.gp import gp_Ax1, gp_Dir, gp_Pnt face_inner_radius = pnt["X"] + (17.0 - wall_thick / 2) * 1000 face_outer_radius = pnt["X"] + (17.0 + wall_thick / 2) * 1000 # point to create an edge from edg_points = [ gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"]), gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"] + height), gp_Pnt(face_outer_radius, pnt["Y"], pnt["Z"] + height), gp_Pnt(face_outer_radius, pnt["Y"], pnt["Z"]), gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"]), ] # aggregate edges in wire hexwire = BRepBuilderAPI_MakeWire() for i in range(len(edg_points) - 1): hexedge = BRepBuilderAPI_MakeEdge(edg_points[i], edg_points[i + 1]).Edge() hexwire.Add(hexedge) hexwire_wire = hexwire.Wire() # face from wire hexface = BRepBuilderAPI_MakeFace(hexwire_wire).Face() revolve_axis = gp_Ax1(gp_Pnt(pnt["X"], pnt["Y"], pnt["Z"]), gp_Dir(0, 0, 1)) # create revolved shape revolved_shape_ = BRepPrimAPI_MakeRevol(hexface, revolve_axis, np.radians( float(revolve_angle))).Shape() revolved_shape_ = rotate_shp_3_axis(revolved_shape_, revolve_axis, rotation) return revolved_shape_
def make_revolve_solid(face: TopoDS_Face, axis, angle, origin) -> TopoDS_Shape: from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeRevol revolve_axis = gp_Ax1(gp_Pnt(origin[0], origin[1], origin[2]), gp_Dir(axis[0], axis[1], axis[2])) revolved_shape = BRepPrimAPI_MakeRevol(face, revolve_axis, np.deg2rad(angle)).Shape() return revolved_shape
def makeCylSection(self,r,h) : print("makeCylSection") import cadquery as cq from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeRevol rect = self.makeRect(r,h) print("rect made") print(self.getDelta()) shape = BRepPrimAPI_MakeRevol(rect,self.RevAxis, \ self.getDelta()).Shape() return shape
def revolved_cut(base): # Define 7 points face_points = TColgp_Array1OfPnt(1, 7) face_inner_radius = 0.6 pts = [ gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05), gp_Pnt(face_inner_radius - 0.10, 0.0, -0.025), gp_Pnt(face_inner_radius - 0.10, 0.0, 0.025), gp_Pnt(face_inner_radius + 0.10, 0.0, 0.025), gp_Pnt(face_inner_radius + 0.10, 0.0, -0.025), gp_Pnt(face_inner_radius + 0.05, 0.0, -0.05), gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05), ] for n, i in enumerate(pts): face_points.SetValue(n + 1, i) # Use these points to create edges and add these edges to a wire hexwire = BRepBuilderAPI_MakeWire() for i in range(1, 7): hexedge = BRepBuilderAPI_MakeEdge(face_points.Value(i), face_points.Value(i + 1)).Edge() hexwire.Add(hexedge) # Turn the wire into a 6 sided face hexface = BRepBuilderAPI_MakeFace(hexwire.Wire()).Face() # Revolve the face around an axis revolve_axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) revolved_shape = BRepPrimAPI_MakeRevol(hexface, revolve_axis).Shape() # Move the generated shape move = gp_Trsf() move.SetTranslation(gp_Pnt(0, 0, 0), gp_Pnt(0, 0, sin(0.5))) moved_shape = BRepBuilderAPI_Transform(revolved_shape, move, False).Shape() # Remove the revolved shape cut = BRepAlgoAPI_Cut(base, moved_shape).Shape() return cut
def revolved_shape(): """ demonstrate how to create a revolved shape from an edge adapted from algotopia.com's opencascade_basic tutorial: http://www.algotopia.com/contents/opencascade/opencascade_basic """ face_inner_radius = 0.6 # point to create an edge from edg_points = [ gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05), gp_Pnt(face_inner_radius - 0.10, 0.0, -0.025), gp_Pnt(face_inner_radius - 0.10, 0.0, 0.025), gp_Pnt(face_inner_radius + 0.10, 0.0, 0.025), gp_Pnt(face_inner_radius + 0.10, 0.0, -0.025), gp_Pnt(face_inner_radius + 0.05, 0.0, -0.05), gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05), ] # aggregate edges in wire hexwire = BRepBuilderAPI_MakeWire() for i in range(6): hexedge = BRepBuilderAPI_MakeEdge(edg_points[i], edg_points[i + 1]).Edge() hexwire.Add(hexedge) hexwire_wire = hexwire.Wire() # face from wire hexface = BRepBuilderAPI_MakeFace(hexwire_wire).Face() revolve_axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) # create revolved shape revolved_shape_ = BRepPrimAPI_MakeRevol(hexface, revolve_axis, math.radians(90.)).Shape() # render wire & revolved shape display.DisplayShape([revolved_shape_, hexwire_wire]) display.FitAll() start_display()
def revolve(): """Revolve profile on active WP to create a new part.""" wp = win.activeWp if win.lineEditStack and len(win.ptStack) == 2: p2 = win.ptStack.pop() p1 = win.ptStack.pop() name = win.lineEditStack.pop() win.clearAllStacks() wireOK = wp.makeWire() if not wireOK: print("Unable to make wire.") return face = BRepBuilderAPI_MakeFace(wp.wire).Shape() revolve_axis = gp_Ax1(p1, gp_Dir(gp_Vec(p1, p2))) revolved_shape = BRepPrimAPI_MakeRevol(face, revolve_axis).Shape() uid = win.getNewPartUID(revolved_shape, name=name) win.statusBar().showMessage('New part created.') win.clearCallback() win.redraw() else: win.registerCallback(revolveC) win.lineEdit.setFocus() statusText = "Pick two points on revolve axis." win.statusBar().showMessage(statusText)
def round_tooth(wedge): round_x = 2.6 round_z = 0.06 * pitch round_radius = pitch # Determine where the circle used for rounding has to start and stop p2d_1 = gp_Pnt2d(top_radius - round_x, 0) p2d_2 = gp_Pnt2d(top_radius, round_z) # Construct the rounding circle round_circle = GccAna_Circ2d2TanRad(p2d_1, p2d_2, round_radius, 0.01) if (round_circle.NbSolutions() != 2): sys.exit(-2) round_circle_2d_1 = round_circle.ThisSolution(1) round_circle_2d_2 = round_circle.ThisSolution(2) if (round_circle_2d_1.Position().Location().Coord()[1] >= 0): round_circle_2d = round_circle_2d_1 else: round_circle_2d = round_circle_2d_2 # Remove the arc used for rounding trimmed_circle = GCE2d_MakeArcOfCircle(round_circle_2d, p2d_1, p2d_2).Value() # Calculate extra points used to construct lines p1 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y()) p2 = gp_Pnt(p2d_2.X(), 0, p2d_2.Y()) p3 = gp_Pnt(p2d_2.X() + 1, 0, p2d_2.Y()) p4 = gp_Pnt(p2d_2.X() + 1, 0, p2d_1.Y() - 1) p5 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y() - 1) # Convert the arc and four extra lines into 3D edges plane = gp_Pln(gp_Ax3(gp_Origin(), gp_DY().Reversed(), gp_DX())) arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_circle, plane)).Edge() lin1 = BRepBuilderAPI_MakeEdge(p2, p3).Edge() lin2 = BRepBuilderAPI_MakeEdge(p3, p4).Edge() lin3 = BRepBuilderAPI_MakeEdge(p4, p5).Edge() lin4 = BRepBuilderAPI_MakeEdge(p5, p1).Edge() # Make a wire composed of the edges round_wire = BRepBuilderAPI_MakeWire(arc1) round_wire.Add(lin1) round_wire.Add(lin2) round_wire.Add(lin3) round_wire.Add(lin4) # Turn the wire into a face round_face = BRepBuilderAPI_MakeFace(round_wire.Wire()).Shape() # Revolve the face around the Z axis over the tooth angle rounding_cut_1 = BRepPrimAPI_MakeRevol(round_face, gp_OZ(), tooth_angle).Shape() # Construct a mirrored copy of the first cutting shape mirror = gp_Trsf() mirror.SetMirror(gp_XOY()) mirrored_cut_1 = BRepBuilderAPI_Transform(rounding_cut_1, mirror, True).Shape() # and translate it so that it ends up on the other side of the wedge translate = gp_Trsf() translate.SetTranslation(gp_Vec(0, 0, thickness)) rounding_cut_2 = BRepBuilderAPI_Transform(mirrored_cut_1, translate, False).Shape() # Cut the wedge using the first and second cutting shape cut_1 = BRepAlgoAPI_Cut(wedge, rounding_cut_1).Shape() cut_2 = BRepAlgoAPI_Cut(cut_1, rounding_cut_2).Shape() return cut_2
def Create_Bk(self, filename="SFU01204-4", ss="BKBF10", L=1000): pass "获取选择零件名称 获取路径" # 获取零件名称 try: pass new_shape = TopoDS_Shape() #filename = "SFU2005-4" # 获取相应零件的路径*************************************** self.partpath = os.getcwd() self.partpath = self.partpath + "\\3Ddata" + "\\STP" + "\\" + filename + ".stp" self.shape = read_step_file(self.partpath) self.shape.Free(True) # 先释放shape # self.new_build.Add(self.aCompound,shape123)#将shaoe添加入复合体 self.new_build.Add(self.aCompound, self.shape) #绘制丝杆************************************************** if int(filename[3:6]) == 12 or int(filename[3:6]) == 14 or int( filename[3:6]) == 15: ss = "BKBF10" elif int(filename[3:6]) == 14 or int(filename[3:6]) == 15 or int( filename[3:6]) == 16 or int(filename[3:6]) == 18: pass ss = "BKBF12" elif int(filename[3:6]) == 18 or int(filename[3:6]) == 20: ss = "BKBF15" elif int(filename[3:6]) == 20 or int(filename[3:6]) == 25: ss = "BKBF17" elif int(filename[3:6]) == 25 or int(filename[3:6]) == 28: ss = "BKBF20" elif int(filename[3:6]) == 32 or int(filename[3:6]) == 36: ss = "BKBF25" elif int(filename[3:6]) == 36 or int(filename[3:6]) == 40: ss = "BKBF30" elif int(filename[3:6]) == 40 or int(filename[3:6]) == 45 or int( filename[3:6]) == 50: ss = "BKBF35" elif int(filename[3:6]) == 50 or int(filename[3:6]) == 55: ss = "BKBF40" self.BK_serise_dict[ss]["D3"] = int(filename[3:6]) #重新设置丝杆直径 #print(filename[3:6]) #PL = (L - 15 - 39 - 10) / 2 ''' PL = (L - self.BK_serise_dict[ss]["L1"] - self.BK_serise_dict[ss]["L3"] - self.BK_serise_dict[ss]["L4"]) / 2 ''' #Center_point=filename[0:] PL = L / 2 #P1 = [0, 0, PL + 39 + 15] P1 = [ 0, 0, PL + self.BK_serise_dict[ss]["L3"] + self.BK_serise_dict[ss]["L1"] ] #P2 = [0, 4, PL + 39 + 15] P2 = [ 0, self.BK_serise_dict[ss]["D1"] / 2, PL + self.BK_serise_dict[ss]["L3"] + self.BK_serise_dict[ss]["L1"] ] #P3 = [0, 4, PL + 39] P3 = [ 0, self.BK_serise_dict[ss]["D1"] / 2, PL + self.BK_serise_dict[ss]["L3"] ] #P4 = [0, 5, PL + 39] P4 = [ 0, self.BK_serise_dict[ss]["D2"] / 2, PL + self.BK_serise_dict[ss]["L3"] ] #P5 = [0, 5, PL] P5 = [0, self.BK_serise_dict[ss]["D2"] / 2, PL] #P6 = [0, 6, PL] P6 = [0, self.BK_serise_dict[ss]["D3"] / 2, PL] #P7 = [0, 6, -PL] P7 = [0, self.BK_serise_dict[ss]["D3"] / 2, -PL] #P8 = [0, 4, -PL] P8 = [0, self.BK_serise_dict[ss]["D4"] / 2, -PL] #P9 = [0, 4, -PL - 7.9] P9 = [ 0, self.BK_serise_dict[ss]["D4"] / 2, -PL - self.BK_serise_dict[ss]["L5"] ] #P10 = [0, 4 - 0.2, -PL - 7.9] P10 = [ 0, self.BK_serise_dict[ss]["D5"] / 2, -PL - self.BK_serise_dict[ss]["L5"] ] #P11 = [0, 4 - 0.2, -PL - 7.9 - 0.8] P11 = [ 0, self.BK_serise_dict[ss]["D5"] / 2, -PL - self.BK_serise_dict[ss]["L5"] - self.BK_serise_dict[ss]["L6"] ] #P12 = [0, 4, -PL - 7.9 - 0.8] P12 = [ 0, self.BK_serise_dict[ss]["D4"] / 2, -PL - self.BK_serise_dict[ss]["L5"] - self.BK_serise_dict[ss]["L6"] ] #P13 = [0, 4, -PL - 10] P13 = [ 0, self.BK_serise_dict[ss]["D4"] / 2, -PL - self.BK_serise_dict[ss]["L4"] ] #P14 = [0, 0, -PL - 10] P14 = [0, 0, -PL - self.BK_serise_dict[ss]["L4"]] E11 = BRepBuilderAPI_MakeEdge(gp_Pnt(P1[0], P1[1], P1[2]), gp_Pnt(P2[0], P2[1], P2[2])).Edge() E12 = BRepBuilderAPI_MakeEdge(gp_Pnt(P2[0], P2[1], P2[2]), gp_Pnt(P3[0], P3[1], P3[2])).Edge() E13 = BRepBuilderAPI_MakeEdge(gp_Pnt(P3[0], P3[1], P3[2]), gp_Pnt(P4[0], P4[1], P4[2])).Edge() E14 = BRepBuilderAPI_MakeEdge(gp_Pnt(P4[0], P4[1], P4[2]), gp_Pnt(P5[0], P5[1], P5[2])).Edge() E15 = BRepBuilderAPI_MakeEdge(gp_Pnt(P5[0], P5[1], P5[2]), gp_Pnt(P6[0], P6[1], P6[2])).Edge() E16 = BRepBuilderAPI_MakeEdge(gp_Pnt(P6[0], P6[1], P6[2]), gp_Pnt(P7[0], P7[1], P7[2])).Edge() E17 = BRepBuilderAPI_MakeEdge(gp_Pnt(P7[0], P7[1], P7[2]), gp_Pnt(P8[0], P8[1], P8[2])).Edge() E18 = BRepBuilderAPI_MakeEdge(gp_Pnt(P8[0], P8[1], P8[2]), gp_Pnt(P9[0], P9[1], P9[2])).Edge() E19 = BRepBuilderAPI_MakeEdge(gp_Pnt(P9[0], P9[1], P9[2]), gp_Pnt(P10[0], P10[1], P10[2])).Edge() E20 = BRepBuilderAPI_MakeEdge(gp_Pnt(P10[0], P10[1], P10[2]), gp_Pnt(P11[0], P11[1], P11[2])).Edge() E21 = BRepBuilderAPI_MakeEdge(gp_Pnt(P11[0], P11[1], P11[2]), gp_Pnt(P12[0], P12[1], P12[2])).Edge() E22 = BRepBuilderAPI_MakeEdge(gp_Pnt(P12[0], P12[1], P12[2]), gp_Pnt(P13[0], P13[1], P13[2])).Edge() E23 = BRepBuilderAPI_MakeEdge(gp_Pnt(P13[0], P13[1], P13[2]), gp_Pnt(P14[0], P14[1], P14[2])).Edge() E24 = BRepBuilderAPI_MakeEdge(gp_Pnt(P14[0], P14[1], P14[2]), gp_Pnt(P1[0], P1[1], P1[2])).Edge() new_charme = ChFi2d_ChamferAPI() new_charme.Init(E11, E12) new_charme.Perform() E25 = new_charme.Result(E11, E12, self.BK_serise_dict[ss]["C1"], self.BK_serise_dict[ss]["C1"]) #倒角1 new_charme.Init(E13, E14) new_charme.Perform() E26 = new_charme.Result(E13, E14, self.BK_serise_dict[ss]["C2"], self.BK_serise_dict[ss]["C2"]) #倒角2 new_charme.Init(E15, E16) new_charme.Perform() E27 = new_charme.Result(E15, E16, self.BK_serise_dict[ss]["C3"], self.BK_serise_dict[ss]["C3"]) #倒角3 new_charme.Init(E16, E17) new_charme.Perform() E28 = new_charme.Result(E16, E17, self.BK_serise_dict[ss]["C3"], self.BK_serise_dict[ss]["C3"]) # 倒角4 new_charme.Init(E22, E23) new_charme.Perform() E29 = new_charme.Result(E22, E23, self.BK_serise_dict[ss]["C1"], self.BK_serise_dict[ss]["C1"]) # 倒角5 #print(type(E11)) #print(E29.IsNull()) W1 = BRepBuilderAPI_MakeWire(E11, E25, E12).Wire() W2 = BRepBuilderAPI_MakeWire(E13, E26, E14).Wire() W3 = BRepBuilderAPI_MakeWire(E15, E27, E16).Wire() W4 = BRepBuilderAPI_MakeWire(E16, E28, E17).Wire() W5 = BRepBuilderAPI_MakeWire(E18, E19, E20, E21).Wire() W6 = BRepBuilderAPI_MakeWire(E22, E29, E23, E24).Wire() #print("succeed") mkWire = BRepBuilderAPI_MakeWire() mkWire.Add(W1) mkWire.Add(W2) mkWire.Add(W3) mkWire.Add(W4) mkWire.Add(W5) mkWire.Add(W6) Rob = BRepPrimAPI_MakeRevol( BRepBuilderAPI_MakeFace(mkWire.Wire()).Face(), gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))).Shape() #倒角----------------------------- #MF=BRepFilletAPI_MakeChamfer(Rob) #MF.Add() #移动 ls_filename = filename[0:8] + "_4" move_distance = 0.5 * L - ( L - float(self.SFU_serise_dict[ls_filename]["L"])) / 2 cone = TopoDS_Shape(Rob) T = gp_Trsf() T.SetTranslation(gp_Vec(0, 0, -move_distance)) loc = TopLoc_Location(T) cone.Location(loc) self.new_build.Add(self.aCompound, cone) print(type(self.aCompound)) return self.aCompound except: return False