def through_sections(): #ruled circle_1 = gp_Circ(gp_Ax2(gp_Pnt(-100., 0., -100.), gp_Dir(0., 0., 1.)), 40.) wire_1 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_1).Edge()).Wire() circle_2 = gp_Circ(gp_Ax2(gp_Pnt(-10., 0., -0.), gp_Dir(0., 0., 1.)), 40.) wire_2 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_2).Edge()).Wire() circle_3 = gp_Circ(gp_Ax2(gp_Pnt(-75., 0., 100.), gp_Dir(0., 0., 1.)), 40.) wire_3 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_3).Edge()).Wire() circle_4 = gp_Circ(gp_Ax2(gp_Pnt(0., 0., 200.), gp_Dir(0., 0., 1.)), 40.) wire_4 = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_4).Edge()).Wire() generatorA = BRepOffsetAPI_ThruSections(False, True) # the use of the map function fails at producing the ThruSection # on py3k. Why ? # map(generatorA.AddWire, [wire_1, wire_2, wire_3, wire_4]) # we have to use a loop for wir in [wire_1, wire_2, wire_3, wire_4]: generatorA.AddWire(wir) generatorA.Build() display.DisplayShape(generatorA.Shape()) #smooth circle_1b = gp_Circ(gp_Ax2(gp_Pnt(100., 0., -100.), gp_Dir(0., 0., 1.)), 40.) wire_1b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_1b).Edge()).Wire() circle_2b = gp_Circ(gp_Ax2(gp_Pnt(210., 0., -0.), gp_Dir(0., 0., 1.)), 40.) wire_2b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_2b).Edge()).Wire() circle_3b = gp_Circ(gp_Ax2(gp_Pnt(275., 0., 100.), gp_Dir(0., 0., 1.)), 40.) wire_3b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_3b).Edge()).Wire() circle_4b = gp_Circ(gp_Ax2(gp_Pnt(200., 0., 200.), gp_Dir(0., 0., 1.)), 40.) wire_4b = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(circle_4b).Edge()).Wire() generatorB = BRepOffsetAPI_ThruSections(True, False) # same here, the following line fails # map(generatorB.AddWire, [wire_1b, wire_2b, wire_3b, wire_4b]) for wir in [wire_1b, wire_2b, wire_3b, wire_4b]: generatorB.AddWire(wir) generatorB.Build() display.DisplayShape(generatorB.Shape(), update=True)
def make_Thru(self, num=50): api = BRepOffsetAPI_ThruSections() print(self.poly.Location().Transformation()) for idx, phi in enumerate(np.linspace(0, 2 * np.pi, num)): ax = self.poly_axs.Rotated(self.axs.Axis(), phi) poly_i = self.poly.Located(set_loc(gp_Ax3(), ax)) # print(poly_i.Location().Transformation()) api.AddWire(poly_i) self.display.DisplayShape(poly_i) api.Build() return api.Shape()
def _loft(arr, smooth=False, shell=False, maxdegree=4): builder = BRepOffsetAPI_ThruSections(not shell, not smooth) builder.SetMaxDegree(maxdegree) for v in arr: if v.Shape().ShapeType() == TopAbs_FACE: raise Exception("Loft argument must be array of Wires or Edges") for r in arr: builder.AddWire(r.Wire_orEdgeToWire()) return Shape(builder.Shape())
def gen_through(self): obj = BRepOffsetAPI_ThruSections() ax2_1 = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) crl_1 = gp_Circ(ax2_1, 100) obj.AddWire(crl_1) ax2_2 = gp_Ax2(gp_Pnt(0, 0, 100), gp_Dir(0, 0, 1)) crl_2 = gp_Circ(ax2_2, 200) obj.AddWire(crl_2) obj.Build() self.display.DisplayShape(obj.Shape())
def make_loft(elements, ruled=False, tolerance=TOLERANCE, continuity=GeomAbs_C2, check_compatibility=True): from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_ThruSections sections = BRepOffsetAPI_ThruSections(False, ruled, tolerance) for i in elements: if isinstance(i, TopoDS_Wire): sections.AddWire(i) elif isinstance(i, TopoDS_Vertex): sections.AddVertex(i) else: raise TypeError('elements is a list of TopoDS_Wire or TopoDS_Vertex, found a %s fool' % i.__class__) sections.CheckCompatibility(check_compatibility) sections.SetContinuity(continuity) sections.Build() with assert_isdone(sections, 'failed lofting'): te = ShapeToTopology() loft = te(sections.Shape()) return loft
def getShapeSkin(pntStart, wires, pntEnd): # Initialize and build skiner = BRepOffsetAPI_ThruSections() skiner.SetSmoothing(True) #skiner.SetMaxDegree(5) vstart = BRepBuilderAPI_MakeVertex(pntStart).Vertex() skiner.AddVertex(vstart) for wire in wires: skiner.AddWire(wire) vend = BRepBuilderAPI_MakeVertex(pntEnd).Vertex() skiner.AddVertex(vend) skiner.Build() return skiner.Shape()
def loft(self, solid=True, ruled=True, precision=0.000001): wires = collect_wires(self) self.children = [] generator = BRepOffsetAPI_ThruSections(solid, ruled, precision) for w in wires: debug("wire: %s" % (str(w), )) generator.AddWire(w) generator.Build() shape = generator.Shape() scls = SCLShape(shape) sclp = SCLPart3(self) sclp.set_shape(scls) name = get_inc_name("loft") sclp.set_name(name) debug("Creating loft %s" % (name, )) self.add_child_context(sclp)
def getDaoSkinningSurface(self, offset): limitPoints = self.getCached('getDaoOffsetPoints', offset) beginPoint = limitPoints['Begin'] endPoint = limitPoints['End'] skinner = BRepOffsetAPI_ThruSections(True) skinner.SetSmoothing(True) beginVertex = BRepBuilderAPI_MakeVertex(beginPoint).Vertex() skinner.AddVertex(beginVertex) ks = self.aSkinningSlicesKs for i in range(len(ks)): sliceWire = self.getCached('getDaoSliceWire', offset, ks[i]) skinner.AddWire(sliceWire) endVertex = BRepBuilderAPI_MakeVertex(endPoint).Vertex() skinner.AddVertex(endVertex) skinner.Build() surface = skinner.Shape() return surface
anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl1) anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2) anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl2) threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1.Edge(), anEdge2OnSurf1.Edge()) threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2.Edge(), anEdge2OnSurf2.Edge()) # Compute the 3D representations of the edges/wires breplib.BuildCurves3d(threadingWire1.Shape()) breplib.BuildCurves3d(threadingWire2.Shape()) # Create the surfaces of the threading aTool = BRepOffsetAPI_ThruSections(True) aTool.AddWire(threadingWire1.Wire()) aTool.AddWire(threadingWire2.Wire()) aTool.CheckCompatibility(False) myThreading = aTool.Shape() # Build the resulting compound bottle = TopoDS_Compound() aBuilder = BRep_Builder() aBuilder.MakeCompound(bottle) aBuilder.Add(bottle, myBody_step3.Shape()) aBuilder.Add(bottle, myThreading) print("bottle created") export_shape_to_svg(bottle, "./test_mypy_classic_occ_bottle.svg") write_step_file(bottle, "./test_mypy_classic_occ_bottle.stp")
ax2 = axs.Ax2() px = np.linspace(-1, 1, 100) * 100 py = np.linspace(-1, 1, 100) * 100 pxy = np.meshgrid(px, py) pz = -1 * (pxy[0]**2 / (2 * r_z) + pxy[1]**2 / (2 * r_z)) pln = surf_spl(*pxy, pz, axs) wxy = Geom_Ellipse(ax2, w_z, w_z).Elips() wxy = BRepBuilderAPI_MakeWire( BRepBuilderAPI_MakeEdge(wxy).Edge()).Wire() print(wxy, pln) api.AddWire(wxy) display.DisplayShape(pnt) display.DisplayShape(pln) display.DisplayShape(wxy) api.Build() surf_wxy = api.Shape() display.DisplayShape(surf_wxy) pnt = gp_Pnt(0, 0, 500) axs = gp_Ax3(pnt, gp_Dir(0, 0, 1)) axs.Rotate(gp_Ax1(axs.Location(), axs.XDirection()), np.deg2rad(5)) axs.Rotate(gp_Ax1(axs.Location(), axs.YDirection()), np.deg2rad(30)) ax2 = axs.Ax2() px = np.linspace(-1, 1, 100) * 100 py = np.linspace(-1, 1, 100) * 100 mesh = np.meshgrid(px, py) surf = mesh[0]**2 / 1000 + mesh[1]**2 / 1000 #pln = make_plane (axs.Location(), dir_to_vec(axs.Direction())) pln = surf_spl(*mesh, surf, axs) display.DisplayShape(pln)
def through_section(sec_a, sec_b, solid_): generator_sec = BRepOffsetAPI_ThruSections(solid_, False) generator_sec.AddWire(sec_a) generator_sec.AddWire(sec_b) generator_sec.Build() return generator_sec.Shape()
class LoftShape(object): """ Loft a shape using a sequence of sections. :param sections: The sections of the loft. These are usually wires but the first and last section can be vertices. Edges are converted to wires before adding to the loft tool. :type sections: collections.Sequence(afem.topology.entities.Vertex or afem.topology.entities.Edge or afem.topology.entities.Wire) :param bool is_solid: If *True* the tool will build a solid, otherwise it will build a shell. :param bool make_ruled: If *True* the faces between sections will be ruled surfaces, otherwise they are smoothed out by approximation. :param float pres3d: Defines the precision for the approximation algorithm. :param bool check_compatibility: Option to check the orientation of the sections to avoid twisted results and update to have the same number of edges. :param bool use_smoothing: Option to use approximation algorithm. :param OCC.Core.Approx.Approx_ParametrizationType par_type: Parametrization type. :param OCC.Core.GeomAbs.GeomAbs_Shape continuity: The desired continuity. :param int max_degree: The maximum degree for the approximation algorithm. :raise TypeError: If any of the sections cannot be added to the tool because they are of the wrong type. """ def __init__(self, sections, is_solid=False, make_ruled=False, pres3d=1.0e-6, check_compatibility=None, use_smoothing=None, par_type=None, continuity=None, max_degree=None): self._tool = BRepOffsetAPI_ThruSections(is_solid, make_ruled, pres3d) if check_compatibility is not None: self._tool.CheckCompatibility(check_compatibility) if use_smoothing is not None: self._tool.SetSmoothing(use_smoothing) if par_type is not None: self._tool.SetParType(par_type) if continuity is not None: self._tool.SetContinuity(continuity) if max_degree is not None: self._tool.SetMaxDegree(max_degree) for section in sections: if section.is_vertex: self._tool.AddVertex(section.object) elif section.is_edge: wire = Wire.by_edge(section) self._tool.AddWire(wire.object) elif section.is_wire: self._tool.AddWire(section.object) else: raise TypeError('Invalid shape type in loft.') self._tool.Build() @property def is_done(self): """ :return: *True* if done, *False* if not. :rtype: bool """ return self._tool.IsDone() @property def shape(self): """ :return: The lofted shape. :rtype: afem.topology.entities.Shape """ return Shape.wrap(self._tool.Shape()) @property def first_shape(self): """ :return: The first/bottom shape of the loft if a solid was constructed. :rtype: afem.topology.entities.Shape """ return Shape.wrap(self._tool.FirstShape()) @property def last_shape(self): """ :return: The last/top shape of the loft if a solid was constructed. :rtype: afem.topology.entities.Shape """ return Shape.wrap(self._tool.LastShape()) @property def max_degree(self): """ :return: The max degree used in the approximation algorithm :rtype: int """ return self._tool.MaxDegree() def generated_face(self, edge): """ Get a face(s) generated by the edge. If the ruled option was used, then this returns each face generated by the edge. If the smoothing option was used, then this returns the face generated by the edge. :param afem.topology.entities.Edge edge: The edge. :return: The face(s) generated by the edge. :rtype: afem.topology.entities.Shape """ return Shape.wrap(self._tool.GeneratedFace(edge.object))
dest="rxy", default=(0, 0), type="float", nargs=2) opt, argc = parser.parse_args(argvs) print(argc, opt) display, start_display, add_menu, add_function_to_menu = init_display() api = BRepOffsetAPI_ThruSections() pt = np.linspace(*opt.lxy, 10) pr_x = np.tan(np.deg2rad(opt.rxy[0])) * pt + opt.radi[0] pr_y = np.tan(np.deg2rad(opt.rxy[1])) * pt + opt.radi[1] for i, d in enumerate(pt): pnt = gp_Pnt(0, 0, pt[i]) d_z = gp_Dir(0, 0, 1) wxy = [pr_x[i], pr_y[i]] obj = wxy_wire(pnt, wxy) display.DisplayShape(obj) api.AddWire(obj) api.Build() surf = api.Shape() display.DisplayShape(surf) export_STEPFile_single(surf, opt.dir + opt.surf + ".stp") display.FitAll() start_display()
fc1 = obj.make_FaceByOrder(pts) fc1.Location(set_loc(gp_Ax3(), ax1)) print(fc1) obj.display.DisplayShape(br1) obj.display.DisplayShape(fc1) ax2 = gp_Ax3() ax2.SetLocation(gp_Pnt(0, 0, 25)) pt2 = np.loadtxt(obj.rootname + "_pln2.txt") print(pt2) pts = [] for xyz in pt2 + [pt2[0]]: pts.append(gp_Pnt(*xyz)) br2 = make_polygon(pts, closed=True) br2.Location(set_loc(gp_Ax3(), ax2)) fc2 = obj.make_FaceByOrder(pts) fc2.Location(set_loc(gp_Ax3(), ax2)) print(fc2) obj.display.DisplayShape(br2) obj.display.DisplayShape(fc2) api = BRepOffsetAPI_ThruSections() api.SetSmoothing(True) api.AddWire(br1) api.AddWire(br2) api.Build() shp = api.Shape() obj.display.DisplayShape(shp) #obj.export_stp(shp) obj.show()
# pt = BRepBuilderAPI_MakeVertex(gp_Pnt(p[0], p[1], p[2])).Shape() # display.DisplayShape(pt) # display the wires #display.DisplayShape(wire_extrados.Shape(), update=True) #display.DisplayShape(wire_intrados.Shape(), update=True) display.DisplayShape(wire.Shape(), update=True) generator_extrados.AddWire(wire_extrados.Wire()) generator_intrados.AddWire(wire_intrados.Wire()) generator_trailing_edge.AddWire(wire_trailing_edge.Wire()) generator.AddWire(wire.Wire()) #start_display() generator_extrados.Build() extrados_shape = generator_extrados.Shape() generator_intrados.Build() intrados_shape = generator_intrados.Shape() generator_trailing_edge.Build() trailing_edge_shape = generator_trailing_edge.Shape() intrados_trailing_edge = generator_trailing_edge.Shape() display.DisplayShape(extrados_shape) display.DisplayShape(intrados_shape) display.DisplayShape(trailing_edge_shape) generator.Build() #display.DisplayShape(generator.Shape()) step_writer = STEPControl_Writer() step_writer.Transfer(extrados_shape, STEPControl_AsIs) step_writer.Transfer(intrados_shape, STEPControl_AsIs)
def get_aligned_boundingbox_ratio(shape, tol=1e-6, optimal_BB=True, ratio=1): """ return the bounding box of the TopoDS_Shape `shape` Parameters ---------- shape : TopoDS_Shape or a subclass such as TopoDS_Face the shape to compute the bounding box from tol: float tolerance of the computed boundingbox use_triangulation : bool, True by default This makes the computation more accurate ratio : float, 1.0 by default. Returns ------- if `as_pnt` is True, return a tuple of gp_Pnt instances for the lower and another for the upper X,Y,Z values representing the bounding box if `as_pnt` is False, return a tuple of lower and then upper X,Y,Z values representing the bounding box """ bbox = Bnd_Box() bbox.SetGap(tol) # note: useTriangulation is True by default, we set it explicitely, but t's not necessary if optimal_BB: use_triangulation = True use_shapetolerance = True brepbndlib_AddOptimal(shape, bbox, use_triangulation, use_shapetolerance) else: brepbndlib_Add(shape, bbox) xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get() dx, mx = (xmax - xmin) * ratio, (xmax + xmin) / 2 dy, my = (ymax - ymin) * ratio, (ymax + ymin) / 2 dz, mz = (zmax - zmin) * ratio, (zmax + zmin) / 2 x0, x1 = mx - dx / 2, mx + dx / 2 y0, y1 = my - dy / 2, my + dy / 2 z0, z1 = mz - dz / 2, mz + dz / 2 corner1 = gp_Pnt(x0, y0, z0) corner2 = gp_Pnt(x1, y1, z1) center = midpoint(corner1, corner2) rim0 = make_polygon([ gp_Pnt(x0, y0, z0), gp_Pnt(x1, y0, z0), gp_Pnt(x1, y1, z0), gp_Pnt(x0, y1, z0) ], closed=True) rim1 = make_polygon([ gp_Pnt(x0, y0, z1), gp_Pnt(x1, y0, z1), gp_Pnt(x1, y1, z1), gp_Pnt(x0, y1, z1) ], closed=True) api = BRepOffsetAPI_ThruSections(True, False, 1.0E-9) api.AddWire(rim0) api.AddWire(rim1) box_shp = api.Shape() #box_shp = BRepPrimAPI_MakeBox(corner1, corner2).Shape() return center, [dx, dy, dz], box_shp
def startBottle(startOnly=True): # minus the neck fillet, shelling & threads partName = "Bottle-start" # The points we'll use to create the profile of the bottle's body aPnt1 = gp_Pnt(-width / 2.0, 0, 0) aPnt2 = gp_Pnt(-width / 2.0, -thickness / 4.0, 0) aPnt3 = gp_Pnt(0, -thickness / 2.0, 0) aPnt4 = gp_Pnt(width / 2.0, -thickness / 4.0, 0) aPnt5 = gp_Pnt(width / 2.0, 0, 0) aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4) aSegment1 = GC_MakeSegment(aPnt1, aPnt2) aSegment2 = GC_MakeSegment(aPnt4, aPnt5) # Could also construct the line edges directly using the points # instead of the resulting line. aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value()) aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value()) aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value()) # Create a wire out of the edges aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge()) # Quick way to specify the X axis xAxis = gp_OX() # Set up the mirror aTrsf = gp_Trsf() aTrsf.SetMirror(xAxis) # Apply the mirror transformation aBRespTrsf = BRepBuilderAPI_Transform(aWire.Wire(), aTrsf) # Get the mirrored shape back out of the transformation # and convert back to a wire aMirroredShape = aBRespTrsf.Shape() # A wire instead of a generic shape now aMirroredWire = topods.Wire(aMirroredShape) # Combine the two constituent wires mkWire = BRepBuilderAPI_MakeWire() mkWire.Add(aWire.Wire()) mkWire.Add(aMirroredWire) myWireProfile = mkWire.Wire() # The face that we'll sweep to make the prism myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile) # We want to sweep the face along the Z axis to the height aPrismVec = gp_Vec(0, 0, height) myBody = BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec) # Add fillets to all edges through the explorer mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape()) anEdgeExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_EDGE) while anEdgeExplorer.More(): anEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(thickness / 12.0, anEdge) anEdgeExplorer.Next() myBody = mkFillet.Shape() # Create the neck of the bottle neckLocation = gp_Pnt(0, 0, height) neckAxis = gp_DZ() neckAx2 = gp_Ax2(neckLocation, neckAxis) myNeckRadius = thickness / 4.0 myNeckHeight = height / 10.0 mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight) myBody = BRepAlgoAPI_Fuse(myBody, mkCylinder.Shape()) if startOnly: # quit here uid = win.getNewPartUID(myBody.Shape(), name=partName) win.redraw() return partName = "Bottle-complete" # Our goal is to find the highest Z face and remove it faceToRemove = None zMax = -1 # We have to work our way through all the faces to find the highest Z face aFaceExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_FACE) while aFaceExplorer.More(): aFace = topods.Face(aFaceExplorer.Current()) if face_is_plane(aFace): aPlane = geom_plane_from_face(aFace) # We want the highest Z face, so compare this to the previous faces aPnt = aPlane.Location() aZ = aPnt.Z() if aZ > zMax: zMax = aZ faceToRemove = aFace aFaceExplorer.Next() facesToRemove = TopTools_ListOfShape() facesToRemove.Append(faceToRemove) myBody = BRepOffsetAPI_MakeThickSolid(myBody.Shape(), facesToRemove, -thickness / 50.0, 0.001) # Set up our surfaces for the threading on the neck neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ()) aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99) aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05) # Set up the curves for the threads on the bottle's neck aPnt = gp_Pnt2d(2.0 * math.pi, myNeckHeight / 2.0) aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0) anAx2d = gp_Ax2d(aPnt, aDir) aMajor = 2.0 * math.pi aMinor = myNeckHeight / 10.0 anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor) anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0) anArc1 = Geom2d_TrimmedCurve(anEllipse1, 0, math.pi) anArc2 = Geom2d_TrimmedCurve(anEllipse2, 0, math.pi) anEllipsePnt1 = anEllipse1.Value(0) anEllipsePnt2 = anEllipse1.Value(math.pi) aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2) # Build edges and wires for threading anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1) anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl1) anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2) anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl2) threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1.Edge(), anEdge2OnSurf1.Edge()) threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2.Edge(), anEdge2OnSurf2.Edge()) # Compute the 3D representations of the edges/wires breplib.BuildCurves3d(threadingWire1.Shape()) breplib.BuildCurves3d(threadingWire2.Shape()) # Create the surfaces of the threading aTool = BRepOffsetAPI_ThruSections(True) aTool.AddWire(threadingWire1.Wire()) aTool.AddWire(threadingWire2.Wire()) aTool.CheckCompatibility(False) myThreading = aTool.Shape() # Build the resulting compound aRes = TopoDS_Compound() aBuilder = BRep_Builder() aBuilder.MakeCompound(aRes) aBuilder.Add(aRes, myBody.Shape()) aBuilder.Add(aRes, myThreading) uid = win.getNewPartUID(aRes, name=partName) win.redraw()
write_step_file(compound, self.tmpdir + "ThruSurf.stp") def display_object(self): self.display.DisplayShape(self.poly) self.display.DisplayShape(self.circle) self.show_axs_pln(self.axs, scale=100) self.show() if __name__ == '__main__': obj = plotocc() obj.SaveMenu() axis1 = gp_Ax3() trf_axs(axis1, [0, 0, 10], [10.0, 10.0, 0.0]) star1 = obj.make_StarWire(axs=axis1, skin=None, radi=[10.0, 8.0]) axis2 = gp_Ax3() trf_axs(axis2, [0, 10, -10], [10.0, 10.0, 5.0]) star2 = obj.make_StarWire(axs=axis2, skin=None, radi=[12.0, 8.0]) api = BRepOffsetAPI_ThruSections() api.AddWire(star1) api.AddWire(star2) api.Build() obj.export_stp(api.Shape()) obj.display.DisplayShape(star1) obj.display.DisplayShape(star2) obj.display.DisplayShape(api.Shape()) obj.show()