def create_part(data): outer_cyl = BRepPrimAPI_MakeCylinder(data["d_out"], data["l"]).Shape() inner_cyl = BRepPrimAPI_MakeCylinder(data["d_in"], data["l"]).Shape() cut = BRepAlgoAPI_Cut() L1 = TopTools_ListOfShape() L1.Append(outer_cyl) L2 = TopTools_ListOfShape() L2.Append(inner_cyl) cut.SetArguments(L1) cut.SetTools(L2) cut.SetFuzzyValue(5e-5) cut.SetRunParallel(False) cut.Build() shape = cut.Shape() anchors = {"bottom": {"p": [0.0, 0.0, 0.0], "u": [0.0, 0.0, -1.0], "v": [1.0, 0.0, 0.0]}, "top": {"p": [0.0, 0.0, data["l"]], "u": [0.0, 0.0, 1.0], "v": [1.0, 0.0, 0.0]}} properties = None return shape, anchors, properties
def clone_tooth(base_shape): clone = gp_Trsf() grouped_shape = base_shape # Find a divisor, between 1 and 8, for the number_of teeth multiplier = 1 max_multiplier = 1 for i in range(0, 8): if num_teeth % multiplier == 0: max_multiplier = i + 1 multiplier = max_multiplier for i in range(1, multiplier): clone.SetRotation(gp_OZ(), -i * tooth_angle) rotated_shape = BRepBuilderAPI_Transform(base_shape, clone, True).Shape() grouped_shape = BRepAlgoAPI_Fuse(grouped_shape, rotated_shape).Shape() # Rotate the basic tooth and fuse together aggregated_shape = grouped_shape for i in range(1, int(num_teeth / multiplier)): clone.SetRotation(gp_OZ(), - i * multiplier * tooth_angle) rotated_shape = BRepBuilderAPI_Transform(grouped_shape, clone, True).Shape() aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape, rotated_shape).Shape() cylinder = BRepPrimAPI_MakeCylinder(gp_XOY(), top_radius - roller_diameter, thickness) aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape, cylinder.Shape()).Shape() return aggregated_shape
def getShape(self, pos, rotation) : import cadquery as cq from OCC.Core.gp import gp_Ax2, gp_Pnt, gp_Dir from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCylinder from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut print("Get Shape gTube") x = pos[0] y = pos[1] z = pos[2] tube1 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(x,y,z), \ gp_Dir(0, 0, 1)),\ self.Radius[1], self.Z).Shape() if self.Radius[0] != 0 : tube2 = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(x,y,z), \ gp_Dir(0, 0, 1)),\ self.Radius[0], self.Z).Shape() tube1 = BRepAlgoAPI_Cut(tube1, tube2).Shape() if self.Sector.completeRev() == False : print("Need to section") if self.Sector.less90() == True : print("Common") shape = self.Sector.makeCommon(self.Radius[1], self.Z, tube1) else : print("Cut") shape = self.Sector.makeCut(self.Radius[1], self.Z, tube1) if self.Sector.getStart() == 0 : return shape else : return self.Sector.rotate(shape) else : return tube1
def create_model(self): cylinder1 = BRepPrimAPI_MakeCylinder( gp_Ax2(getGpPt(self.p1), getGpDir(self.shaftDir)), self.r, self.H).Shape() cylinder2 = BRepPrimAPI_MakeCylinder( gp_Ax2(getGpPt(self.p1), getGpDir(self.shaftDir)), self.r - self.T, self.H).Shape() prism = BRepAlgoAPI_Cut(cylinder1, cylinder2).Shape() return prism
def addNeck(): neckLocation = gp_Pnt(0, 0, height) neckNormal = gp_DZ() neckAx2 = gp_Ax2(neckLocation, neckNormal) myNeckRadius = thickness / 4. myNeckHeight = height / 10. MKCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight) myNeck = MKCylinder.Shape() return myNeck
def testTopoDS_byref_arguments(self): ''' Test byref pass arguments to TopoDS ''' cyl1 = BRepPrimAPI_MakeCylinder(10., 10.).Shape() cyl2 = BRepPrimAPI_MakeCylinder(100., 50.).Shape() c = TopoDS_Compound() bb = TopoDS_Builder() bb.MakeCompound(c) for child in [cyl1, cyl2]: bb.Add(c, child)
def test_TopoDS_byref_arguments(self) -> None: ''' Test byref pass arguments to TopoDS ''' cyl1 = BRepPrimAPI_MakeCylinder(10., 10.).Shape() cyl2 = BRepPrimAPI_MakeCylinder(100., 50.).Shape() c = TopoDS_Compound() self.assertTrue(c.IsNull()) bb = TopoDS_Builder() bb.MakeCompound(c) for child in [cyl1, cyl2]: bb.Add(c, child) self.assertFalse(c.IsNull())
def addNeck(event=None): newPrtName = 'bodyWithNeck' workPart = win.activePart wrkPrtUID = win.activePartUID neckLocation = gp_Pnt(0, 0, height) neckNormal = gp_DZ() neckAx2 = gp_Ax2(neckLocation, neckNormal) myNeckRadius = thickness / 4. myNeckHeight = height / 10. MKCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight) myNeck = MKCylinder.Shape() myBody = BRepAlgoAPI_Fuse(workPart, myNeck).Shape() win.getNewPartUID(myBody, name=newPrtName, ancestor=wrkPrtUID) win.statusBar().showMessage('Add neck complete') win.redraw()
def New_shp(Xmax, Xmin, Ymax, Ymin, Zmax, Zmin, X, Y, Z): Index = random.randint(1, 4) position = cal_position(Xmax, Xmin, Ymax, Ymin, Zmax, Zmin) A = (X + Y + Z) / 5 if Index == 1: X1 = random.uniform(0.5 * A, A) Y1 = random.uniform(0.5 * A, A) Z1 = random.uniform(0.5 * A, A) nshp = BRepPrimAPI_MakeBox( gp_Pnt(-0.5 * X1 + position[0], -0.5 * Y1 + position[1], -0.5 * Z1 + position[2]), X1, Y1, Z1).Shape() if Index == 2: R = random.uniform(0.25 * A, 0.5 * A) nshp = BRepPrimAPI_MakeSphere( gp_Pnt(position[0], position[1], position[2]), R).Shape() if Index == 3: R2 = random.uniform(0.25 * A, 0.5 * A) H = random.uniform(0.5 * A, A) origin = gp_Ax2( gp_Pnt(position[0], position[1], -0.5 * H + position[2]), gp_Dir(0.0, 0.0, 1.0)) nshp = BRepPrimAPI_MakeCone(origin, R2, 0, H).Shape() if Index == 4: R = random.uniform(0.25 * A, 0.5 * A) H = random.uniform(0.5 * A, A) cylinder_origin = gp_Ax2( gp_Pnt(position[0], position[1], -0.5 * H + position[2]), gp_Dir(0.0, 0.0, 1.0)) nshp = BRepPrimAPI_MakeCylinder(cylinder_origin, R, H).Shape() return nshp
def make_cylinder(p, vec, h, r, t=None): """ :param p: :param vec: :param h: :param r: :param t: Wall thickness (if applicable). Will make a :return: """ cylinder_origin = gp_Ax2(gp_Pnt(p[0], p[1], p[2]), gp_Dir(vec[0], vec[1], vec[2])) cylinder = BRepPrimAPI_MakeCylinder(cylinder_origin, r, h).Shape() if t is not None: cutout = BRepPrimAPI_MakeCylinder(cylinder_origin, r - t, h).Shape() return BRepAlgoAPI_Cut(cylinder, cutout).Shape() else: return cylinder
def makeCyl(): """Quick cylinder used for debuggging""" name = "Cylinder" myBody = BRepPrimAPI_MakeCylinder(40, 80).Shape() uid = doc.addComponent(myBody, name, DEFAULT_COLOR) win.build_tree() win.setActivePart(uid) win.draw_shape(uid) win.syncUncheckedToHideList()
def display_fiber(lay, col, nozz_dia): axis = gp_Ax2() for i in range(1, len(lay)): distance = lay[i - 1][0].Distance(lay[i][0]) if distance < 8: ray = gp_Dir(gp_Vec(lay[i - 1][0], lay[i][0])) axis.SetLocation(lay[i - 1][0]) axis.SetDirection(ray) cylinder = BRepPrimAPI_MakeCylinder(axis, nozz_dia / 2, distance) if i < len(lay) - 1: display.DisplayShape(cylinder.Shape(), color=col, update=False) else: display.DisplayShape(cylinder.Shape(), color=col, update=True)
def getDaoCase(r, bevel, decor, h): r2 = r * 2 h2 = h / 2 rTop = r + 2 * bevel + decor rSphere = gp_Vec(0, rTop, h2).Magnitude() sphere = BRepPrimAPI_MakeSphere(rSphere).Shape() limit = BRepPrimAPI_MakeBox(gp_Pnt(-r2, -r2, -h2), gp_Pnt(r2, r2, h2)).Shape() case = BRepAlgoAPI_Common(sphere, limit).Shape() case = getShapeTranslate(case, 0, 0, -h2) cylOut = BRepPrimAPI_MakeCylinder(r + bevel + decor, decor * 2).Shape() #SceneDrawShape('out',cylOut) cylIn = BRepPrimAPI_MakeCylinder(r + bevel, decor * 3).Shape() #SceneDrawShape('in',cylIn) bevelTool = BRepAlgoAPI_Cut(cylOut, cylIn).Shape() bevelTool = getShapeTranslate(bevelTool, 0, 0, -bevel / 2) #SceneDrawShape('tool',bevelTool) case = BRepAlgoAPI_Cut(case, bevelTool).Shape() return case
def boolean_cut(base): # Create a cylinder cylinder_radius = 0.25 cylinder_height = 2.0 cylinder_origin = gp_Ax2(gp_Pnt(0.0, 0.0, - cylinder_height / 2.0), gp_Dir(0.0, 0.0, 1.0)) cylinder = BRepPrimAPI_MakeCylinder(cylinder_origin, cylinder_radius, cylinder_height) # Repeatedly move and subtract it from the input shape move = gp_Trsf() boolean_result = base clone_radius = 1.0 for clone in range(8): angle = clone * pi / 4.0 # Move the cylinder move.SetTranslation(gp_Vec(cos(angle) * clone_radius, sin(angle) * clone_radius, 0.0)) moved_cylinder = BRepBuilderAPI_Transform(cylinder.Shape(), move, True).Shape() # Subtract the moved cylinder from the drilled sphere boolean_result = BRepAlgoAPI_Cut(boolean_result, moved_cylinder).Shape() return boolean_result
def build_shape(x,y,z,dir1): point1=gp_Pnt(x,y,z) if type(dir1)!=int: dir1=gp_Dir(dir1[0],dir1[1],dir1[2]) else: dir1=gp_Dir(0,0,10) axis1=gp_Ax2(point1,dir1) boxshp = BRepPrimAPI_MakeCylinder(axis1,2,20).Shape() ais_boxshp = display.DisplayShape(boxshp,color = "RED", transparency = 0.1, update=True)[0] return ais_boxshp
class CylinderByAxis(object): """ Create a cylinder. :param float radius: The radius. :param float height: The height. :param axis2: Not yet implemented. Solid will be constructed in xy-plane. :raise NotImplementedError: If an axis is provided. """ def __init__(self, radius, height, axis2=None): if axis2 is None: self._builder = BRepPrimAPI_MakeCylinder(radius, height) else: raise NotImplementedError('Providing Axis2 not yet implemented.') @property def face(self): """ :return: The lateral face of the cylinder :rtype: afem.topology.entities.Face """ return Face(self._builder.Face()) @property def shell(self): """ :return: The cylinder as a shell. :rtype: afem.topology.entities.Shell """ return Shell(self._builder.Shell()) @property def solid(self): """ :return: The cylinder as a solid. :rtype: afem.topology.entities.Solid """ return Solid(self._builder.Solid())
def create_model(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = self.T * -self.wDir # extrudeDir is a numpy array prism = makePrismFromFace(aFace, extrudeDir) cylOrigin = self.sec_origin innerCyl = BRepPrimAPI_MakeCylinder( gp_Ax2(getGpPt(cylOrigin), getGpDir(-self.wDir)), self.d / 2, self.T + 1).Shape() prism = BRepAlgoAPI_Cut(prism, innerCyl).Shape() return prism
def create_model(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = -self.T * self.shaftDir # extrudeDir is a numpy array boltHead = makePrismFromFace(aFace, extrudeDir) cylOrigin = self.origin boltCylinder = BRepPrimAPI_MakeCylinder( gp_Ax2(getGpPt(cylOrigin), getGpDir(self.shaftDir)), self.r, self.H).Shape() whole_Bolt = BRepAlgoAPI_Fuse(boltHead, boltCylinder).Shape() return whole_Bolt
def cylinder(self, r, r1, r2, d, d1, d2, h, center=False): nr1 = None nr2 = None nh = None if (not is_var_set(d)) and is_var_set(r): nr1 = r nr2 = r elif is_var_set(d) and (not is_var_set(r)): nr1 = d / 2.0 nr2 = d / 2.0 elif is_var_set(d) and is_var_set(r): nr1 = d / 2.0 nr2 = d / 2.0 elif (not is_var_set(d)) and (not is_var_set(r)) and ( is_var_set(r1) and is_var_set(r2)): nr1 = r1 nr2 = r2 elif (not is_var_set(d)) and (not is_var_set(r)) and ( is_var_set(d1) and is_var_set(d2)): nr1 = d1 / 2.0 nr2 = d2 / 2.0 else: nr1 = 0.5 nr2 = 0.5 nh = 1.0 if is_var_set(h): nh = h ax = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) s = None if nr1 == nr2: s = BRepPrimAPI_MakeCylinder(ax, nr1, nh).Shape() else: s = BRepPrimAPI_MakeCone(ax, nr1, nr2, nh).Shape() scls = SCLShape(s) if (center): debug("center cylinder") trsf = gp_Trsf() trsf.SetTranslation(gp_Vec(0, 0, -h / 2.0)) scls.transform(trsf) sclp = SCLPart3(self) sclp.set_shape(scls) name = get_inc_name("cylinder") sclp.set_name(name) debug("Creating cylinder %s" % (name, )) self.add_child_context(sclp)
def mounting_holes(base): result = base for i in range(0, mounting_hole_count): center = gp_Pnt(cos(i * M_PI / 3) * mounting_radius, sin(i * M_PI / 3) * mounting_radius, 0.0) center_axis = gp_Ax2(center, gp_DZ()) cylinder = BRepPrimAPI_MakeCylinder(center_axis, hole_radius, thickness).Shape() result = BRepAlgoAPI_Cut(result, cylinder).Shape() cone = BRepPrimAPI_MakeCone(center_axis, hole_radius + thickness / 2., hole_radius, thickness / 2.) result = BRepAlgoAPI_Cut(result, cone.Shape()).Shape() return result
def fillet_cylinder(event=None): display.EraseAll() # Create Cylinder cylinder = BRepPrimAPI_MakeCylinder( gp_Ax2(gp_Pnt(-300, 0, 0), gp_Dir(0, 0, 1)), 100, 200).Shape() fillet = BRepFilletAPI_MakeFillet(cylinder) display.DisplayShape(cylinder, update=True) tab_point_2 = TColgp_Array1OfPnt2d(0, 20) for i in range(0, 20): point_2d = gp_Pnt2d(i * 2 * pi / 19, 60 * cos(i * pi / 19 - pi / 2) + 10) tab_point_2.SetValue(i, point_2d) display.DisplayShape(point_2d) expl2 = TopologyExplorer(cylinder).edges() fillet.Add(tab_point_2, next(expl2)) fillet.Build() if fillet.IsDone(): law_evolved_cylinder = fillet.Shape() display.DisplayShape(law_evolved_cylinder, update=True) else: print("fillet not done.")
def from_cylinder(cls, cylinder: compas.geometry.Cylinder) -> 'BRep': """Construct a BRep from a COMPAS cylinder. Parameters ---------- cylinder : :class:`~compas.geometry.Cylinder` Returns ------- :class:`~compas_occ.brep.BRep` """ plane = cylinder.circle.plane height = cylinder.height radius = cylinder.circle.radius frame = Frame.from_plane(plane) frame.transform(Translation.from_vector(frame.zaxis * (-0.5 * height))) ax2 = gp_Ax2(gp_Pnt(*frame.point), gp_Dir(*frame.zaxis), gp_Dir(*frame.xaxis)) brep = BRep() brep.shape = BRepPrimAPI_MakeCylinder(ax2, radius, height).Shape() return brep
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()
# # Get Context # ais_context = display.GetContext() # # Get Prs3d_drawer from previous context # drawer = ais_context.DefaultDrawer() drawer.SetIsoOnPlane(True) la = drawer.LineAspect() la.SetWidth(4) # increase line width in the current viewer # This is only viewed in the HLR mode (hit 'e' key for instance) line_aspect = drawer.SeenLineAspect() drawer.EnableDrawHiddenLine() line_aspect.SetWidth(4) # drawer.SetWireAspect(line_aspect) # # Displays a cylinder # s = BRepPrimAPI_MakeCylinder(50., 50.).Shape() display.DisplayShape(s) # # Display settings and display loop # display.View_Iso() display.FitAll() start_display()
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCylinder from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut from OCC.Core.TopTools import TopTools_ListOfShape outer_cyl = BRepPrimAPI_MakeCylinder(2., 10.).Shape() inner_cyl = BRepPrimAPI_MakeCylinder(1., 10.).Shape() cut = BRepAlgoAPI_Cut() L1 = TopTools_ListOfShape() L1.Append(outer_cyl) L2 = TopTools_ListOfShape() L2.Append(inner_cyl) cut.SetArguments(L1) cut.SetTools(L2) cut.SetFuzzyValue(5e-5) cut.SetRunParallel(False) cut.Build() __shape__ = cut.Shape() __anchors__ = { "bottom": { "p": [0.0, 0.0, 0.0], "u": [0.0, 0.0, -1.0], "v": [1.0, 0.0, 0.0] }, "top": { "p": [0.0, 0.0, 10.0], "u": [0.0, 0.0, 1.0], "v": [1.0, 0.0, 0.0] } }
def simulate(suction_Dia,point_list,angle,material_box): boolean_result=material_box n=0 for j in range(len(point_list)-1): point1=point_list[j] point2=point_list[j+1] #making a cylinder to boolean_cut from material box to simulate powder removing process dir2=gp_Dir(point2[0]-point1[0],point2[1]-point1[1],point2[2]-point1[2]) length=math.sqrt((point2[0]-point1[0])**2+(point2[1]-point1[1])**2+(point2[2]-point1[2])**2)+2 axis1=gp_Ax2(gp_Pnt(point1[0],point1[1],point1[2]),dir2) plan1=gp_Pln(gp_Pnt(point1[0],point1[1],point1[2]),dir2) vec1=gp_Vec(gp_Pnt(point1[0],point1[1],point1[2]),gp_Pnt(point2[0],point2[1],point2[2])) face1=BRepBuilderAPI_MakeFace(plan1,-suction_Dia/2,suction_Dia/2,-suction_Dia/2,suction_Dia/2) ''' my_cylinder_simulation=BRepPrimAPI_MakePrism(face1.Face(),vec1).Shape() edge1=BRepBuilderAPI_MakeEdge(gp_Pnt(point1[0],point1[1],point1[2]),gp_Pnt(point2[0],poin2[1],point2[2])) aWire1=BRepBuilderAPI_MakeWire(edge1.Edge())''' my_cylinder_simulation = BRepPrimAPI_MakeCylinder(axis1,suction_Dia/2,length).Shape() #boolean_result1=BRepAlgoAPI_Cut(boolean_result.Shape(), my_cylinder_simulation) #if boolean_result1.IsDone(): #boolean_result=BRepAlgoAPI_Cut(boolean_result.Shape(), my_cylinder_simulation) tol=1e-3 parallel=True shape_A=boolean_result.Shape() shape_B=my_cylinder_simulation cut = BRepAlgoAPI_Cut() L1 = TopTools_ListOfShape() L1.Append(shape_A) L2 = TopTools_ListOfShape() L2.Append(shape_B) cut.SetArguments(L1) cut.SetTools(L2) cut.SetFuzzyValue(tol) cut.SetRunParallel(parallel) cut.Build() boolean_result=cut if j==0: ais_boolean_shp1 = display.DisplayShape(boolean_result.Shape(),color = "BLACK", transparency = 0, update=True)[0] ais_boolean_shp2 = display.DisplayShape(boolean_result.Shape(),color = "BLACK", transparency = 0, update=True)[0] mymove=make_move(point1,point2,angle) display.Context.Remove(ais_boolean_shp1,True) elif j==(len(point_list)-2): display.Context.Remove(ais_boolean_shp1,True) display.Context.Remove(ais_boolean_shp2,True) elif j%2==0 : ais_boolean_shp2 = display.DisplayShape(boolean_result.Shape(),color = "BLACK", transparency = 0, update=True)[0] mymove=make_move(point1,point2,angle) display.Context.Remove(ais_boolean_shp1,True) else: ais_boolean_shp1 = display.DisplayShape(boolean_result.Shape(),color = "BLACK", transparency = 0, update=True)[0] mymove=make_move(point1,point2,angle) display.Context.Remove(ais_boolean_shp2,True) return boolean_result
#!/usr/bin/env python # coding: utf-8 # In[ ]: from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeCylinder from OCC.Core.gp import gp_Pnt # In[ ]: my_renderer = JupyterRenderer() # In[ ]: box_shape = BRepPrimAPI_MakeBox(10, 20, 30).Shape() cylinder_shape = BRepPrimAPI_MakeCylinder(10, 30).Shape() # In[ ]: vertices = [gp_Pnt(5, 10, 40), gp_Pnt(10, -4, -10)] my_renderer.DisplayShape(vertices) # In[ ]: my_renderer.DisplayShape(cylinder_shape, render_edges=True, topo_level="Face", shape_color="#abdda4", update=True)
def variable_filleting(event=None): display.EraseAll() # Create Box Box = BRepPrimAPI_MakeBox(200, 200, 200).Shape() # Fillet Rake = BRepFilletAPI_MakeFillet(Box) ex = TopologyExplorer(Box).edges() next(ex) next(ex) next(ex) Rake.Add(8, 50, next(ex)) Rake.Build() if Rake.IsDone(): evolvedBox = Rake.Shape() display.DisplayShape(evolvedBox) else: print("Rake not done.") # Create Cylinder Cylinder = BRepPrimAPI_MakeCylinder( gp_Ax2(gp_Pnt(-300, 0, 0), gp_Dir(0, 0, 1)), 100, 200).Shape() fillet_ = BRepFilletAPI_MakeFillet(Cylinder) TabPoint2 = TColgp_Array1OfPnt2d(0, 20) for i in range(0, 20): Point2d = gp_Pnt2d(i * 2 * pi / 19, 60 * cos(i * pi / 19 - pi / 2) + 10) TabPoint2.SetValue(i, Point2d) exp2 = TopologyExplorer(Cylinder).edges() fillet_.Add(TabPoint2, next(exp2)) fillet_.Build() if fillet_.IsDone(): LawEvolvedCylinder = fillet_.Shape() display.DisplayShape(LawEvolvedCylinder) else: print("fillet not done.") ## TODO : fillet not done P = gp_Pnt(350, 0, 0) Box2 = BRepPrimAPI_MakeBox(P, 200, 200, 200).Shape() afillet = BRepFilletAPI_MakeFillet(Box2) TabPoint = TColgp_Array1OfPnt2d(1, 6) P1 = gp_Pnt2d(0., 8.) P2 = gp_Pnt2d(0.2, 16.) P3 = gp_Pnt2d(0.4, 25.) P4 = gp_Pnt2d(0.6, 55.) P5 = gp_Pnt2d(0.8, 28.) P6 = gp_Pnt2d(1., 20.) TabPoint.SetValue(1, P1) TabPoint.SetValue(2, P2) TabPoint.SetValue(3, P3) TabPoint.SetValue(4, P4) TabPoint.SetValue(5, P5) TabPoint.SetValue(6, P6) exp = TopologyExplorer(Box2).edges() next(exp) next(exp) next(exp) afillet.Add(TabPoint, next(exp)) afillet.Build() if afillet.IsDone(): LawEvolvedBox = afillet.Shape() display.DisplayShape(LawEvolvedBox) else: print("aFillet not done.") display.FitAll()
""" bbox = Bnd_Box() bbox.SetGap(tol) if use_mesh: mesh = BRepMesh_IncrementalMesh() mesh.SetParallel(True) mesh.SetShape(shape) mesh.Perform() if not mesh.IsDone(): raise AssertionError("Mesh not done.") brepbndlib_Add(shape, bbox, use_mesh) xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get() return xmin, ymin, zmin, xmax, ymax, zmax, xmax - xmin, ymax - ymin, zmax - zmin print("Box bounding box computation") box_shape = BRepPrimAPI_MakeBox(10., 20., 30.).Shape() bb1 = get_boundingbox(box_shape) print(bb1) print("Cylinder bounding box computation") cyl_shape = BRepPrimAPI_MakeCylinder(10., 20.).Shape() bb2 = get_boundingbox(cyl_shape) print(bb2) print("Torus bounding box computation") torus_shape = BRepPrimAPI_MakeCylinder(15., 5.).Shape() bb3 = get_boundingbox(torus_shape) print(bb3)
def __init__(self, radius, height, axis2=None): if axis2 is None: self._builder = BRepPrimAPI_MakeCylinder(radius, height) else: raise NotImplementedError('Providing Axis2 not yet implemented.')