Python Part.makeCylinder() Examples

The following are 15 code examples of Part.makeCylinder(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Part , or try the search function .
Example #1
Source File: pipeFeatures.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def execute(self, fp):
    base=Part.Face(Part.Wire(Part.makeCircle(fp.D/2)))
    if fp.d>0:
      base=base.cut(Part.Face(Part.Wire(Part.makeCircle(fp.d/2))))
    if fp.n>0:
      hole=Part.Face(Part.Wire(Part.makeCircle(fp.f/2,FreeCAD.Vector(fp.df/2,0,0),FreeCAD.Vector(0,0,1))))
      hole.rotate(FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1),360.0/fp.n/2)
      for i in list(range(fp.n)):
        base=base.cut(hole)
        hole.rotate(FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1),360.0/fp.n)
    flange = base.extrude(FreeCAD.Vector(0,0,fp.t))
    try: # Flange2: raised-face and welding-neck
      if fp.trf>0 and fp.drf>0:
        rf=Part.makeCylinder(fp.drf/2,fp.trf,vO,vZ*-1).cut(Part.makeCylinder(fp.d/2,fp.trf,vO,vZ*-1))
        flange=flange.fuse(rf)
      if fp.dwn>0 and fp.twn>0 and fp.ODp>0:
        wn=Part.makeCone(fp.dwn/2,fp.ODp/2,fp.twn,vZ*float(fp.t)).cut(Part.makeCylinder(fp.d/2,fp.twn,vZ*float(fp.t)))
        flange=flange.fuse(wn)
    except:
      pass
    fp.Shape = flange
    fp.Ports=[FreeCAD.Vector(),FreeCAD.Vector(0,0,float(fp.t))]
    super(Flange,self).execute(fp) # perform common operations 
Example #2
Source File: pipeFeatures.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def execute(self, fp):
    if fp.thk>fp.OD/2:
      fp.thk=fp.OD/2.1
    fp.ID=fp.OD-2*fp.thk
    fp.Profile=str(fp.OD)+"x"+str(fp.thk)
    D=float(fp.OD)
    s=float(fp.thk)
    sfera=Part.makeSphere(0.8*D,FreeCAD.Vector(0,0,-(0.55*D-6*s)))
    cilindro=Part.makeCylinder(D/2,D*1.7,FreeCAD.Vector(0,0,-(0.55*D-6*s+1)),FreeCAD.Vector(0,0,1))
    common=sfera.common(cilindro)
    fil=common.makeFillet(D/6.5,common.Edges)
    cut=fil.cut(Part.makeCylinder(D*1.1,D*2,FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,-1)))
    cap=cut.makeThickness([f for f in cut.Faces if type(f.Surface)==Part.Plane],-s,1.e-3)
    fp.Shape = cap
    fp.Ports=[FreeCAD.Vector()]
    super(Cap,self).execute(fp) # perform common operations 
Example #3
Source File: friki.py    From videoblog with GNU General Public License v2.0 6 votes vote down vote up
def vectorz(l = 10, l_arrow = 4, d = 1, mark = False, show = True):
	"""Draw a vector in the z axis. Parameters:
		 l : Lenght
         l_arrow: arrow length
		 d : vector diameter
	"""

	#-- Correct the length
	if (l < l_arrow):
		l_arrow = l/2

	vectz = Part.makeCylinder(d / 2.0, l - l_arrow)
	base = Part.makeSphere(d / 2.0)
	arrow = Part.makeCone(d/2 + 1, 0.2, l_arrow)
	arrow.Placement.Base.z = l - l_arrow

	#-- Create the union of all the parts
	union = vectz.fuse(base)
	union = union.fuse(arrow)

	#-- Return de vector z
	return union 
Example #4
Source File: HelicalSweepFP.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def sweep_wire(self, w, solid=False):
        faces = []
        for e in w.Edges:
            faces.append(self.sweep_edge(e,solid))
        shell = Part.Shell(faces)
        shell.sewShape()
        if solid:
            cyl = Part.makeCylinder(self.max_radius*2, self.nb_of_turns*self.lead)
            cyl.Placement = self._placement.multiply(FreeCAD.Placement(FreeCAD.Vector(),FreeCAD.Vector(1,0,0),-90))
            common = cyl.common(shell)
            cut_faces = common.Faces
            new_edges = []
            for e1 in common.Edges:
                found = False
                for e2 in shell.Edges:
                    if nurbs_tools.is_same(e1.Curve, e2.Curve, tol=1e-7, full=False):
                        found = True
                        #print("found similar edges")
                        continue
                if not found:
                    new_edges.append(e1)
            #print(len(Part.sortEdges(new_edges)))
            el1, el2 = Part.sortEdges(new_edges)[0:2]
            f1 = Part.makeFace(Part.Wire(el1),'Part::FaceMakerSimple')
            f2 = Part.makeFace(Part.Wire(el2),'Part::FaceMakerSimple')
            cut_faces.extend([f1,f2])
            try:
                shell = Part.Shell(cut_faces)
                shell.sewShape()
                return Part.Solid(shell)
            except Part.OCCError:
                print("Failed to create solid")
                return Part.Compound(cut_faces)
        return shell 
Example #5
Source File: Outline_FP.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def execute(self, obj):
        o = obj.Source
        base = o.Shape.BoundBox.Center
        dl = o.Shape.BoundBox.DiagonalLength
        cyl = Part.makeCylinder(dl, dl*2, base-obj.Direction*dl, obj.Direction).Face1

        uf,ul,vf,vl=cyl.ParameterRange
        pts = list()
        for i in range(obj.RadialSamples):
            u = uf + (float(i)/(obj.RadialSamples-1))*(ul-uf)
            e = cyl.Surface.uIso(u).toShape()
            #best = 1e50
            #good_pt = None
            d,pt,info = o.Shape.distToShape(e)
            if len(pt) > 1:
                debug("multi pt %s"%str(pt))
                #good_point = pt[0][0]
            for i,inf in enumerate(info):
                if inf[0] in (b"Face","Face"):
                    pts.append(pt[i][0])


        if hasattr(obj,"ExtensionProxy"):
            if obj.Active:
                obj.Shape = obj.ExtensionProxy.approximate(obj, pts)
                return()
        bs = Part.BSplineCurve()
        bs.approximate(pts)
        obj.Shape = bs.toShape() 
Example #6
Source File: comp_spring.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def path3d(self):
        cyl = Part.makeCylinder((self.diameter-self.wire_diam)/2., self.length-self.wire_diam, Vector(), Vector(0,0,1)).Face1
        return self.path2d().toShape(cyl.Surface) 
Example #7
Source File: curveOnSurface.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def linearDeviation(edge, radius=1.0):
    sp = edge.valueAt(edge.FirstParameter)
    ep = edge.valueAt(edge.LastParameter)
    axis = ep-sp
    cyl = Part.makeCylinder(radius,axis.Length,sp,axis)
    d,pts,info = edge.distToShape(cyl.Face1)
    params = list()
    for i in info:
        if i[0] in ("Edge",b"Edge"):
            params.append(i[2])
        elif i[0] in ("Vertex",b"Vertex"):
            params.append(edge.parameterAt(edge.Vertexes[i[1]]))
    return (radius-d), params 
Example #8
Source File: pipeFeatures.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def execute(self, fp):
    if fp.thk>fp.OD/2:
      fp.thk=fp.OD/2
    fp.ID=fp.OD-2*fp.thk
    fp.Profile=str(fp.OD)+"x"+str(fp.thk)
    if fp.ID:
      fp.Shape = Part.makeCylinder(fp.OD/2,fp.Height).cut(Part.makeCylinder(fp.ID/2,fp.Height))
    else:
      fp.Shape = Part.makeCylinder(fp.OD/2,fp.Height)
    fp.Ports=[FreeCAD.Vector(),FreeCAD.Vector(0,0,float(fp.Height))]
    super(Pipe,self).execute(fp) # perform common operations 
Example #9
Source File: shapes.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def makeCylinder(cls, radius, height, pnt=Vector(0, 0, 0), dir=Vector(0, 0, 1), angleDegrees=360):
        """
        makeCylinder(radius,height,[pnt,dir,angle]) --
        Make a cylinder with a given radius and height
        By default pnt=Vector(0,0,0),dir=Vector(0,0,1) and angle=360'
        """
        return Shape.cast(FreeCADPart.makeCylinder(radius, height, pnt.wrapped, dir.wrapped, angleDegrees)) 
Example #10
Source File: crosspart.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def make_dog_bone_on_xz(pos_x, pos_z, width, radius):
    cylinder = Part.makeCylinder(radius, width, FreeCAD.Vector(pos_x, -width/2.0, pos_z), FreeCAD.Vector(0, 1, 0))
    return cylinder 
Example #11
Source File: crosspart.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def make_dog_bone_on_yz(pos_y, pos_z, length, radius):
    cylinder = Part.makeCylinder(radius, length, FreeCAD.Vector(-length / 2.0, pos_y, pos_z), FreeCAD.Vector(1, 0, 0))
    return cylinder 
Example #12
Source File: helper.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def make_dog_bone_on_xy(pos_x, pos_y, height, radius):
    cylinder = Part.makeCylinder(radius, height, FreeCAD.Vector(pos_x, pos_y, -height / 2.0), FreeCAD.Vector(0, 0, 1))
    return cylinder 
Example #13
Source File: helper.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def make_dog_bone_on_yz(pos_y, pos_z, height, radius):
    cylinder = Part.makeCylinder(radius, height, FreeCAD.Vector(0, pos_y, pos_z), FreeCAD.Vector(1., 0, 0))
    return cylinder 
Example #14
Source File: join.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def screw_way_on_plane(material_plane, screw_nut_spec, pos_y):
    # horizontal hole
    radius = (screw_nut_spec.screw_diameter * 1.2 - material_plane.laser_beam_diameter) / 2.0
    cylinder = Part.makeCylinder(radius, material_plane.thickness, FreeCAD.Vector(0, 0, -material_plane.thickness / 2.))
    cylinder.rotate(FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(0, 1, 0), 90)
    cylinder.translate(FreeCAD.Vector(material_plane.thickness / 2.0, pos_y, 0.))
    return cylinder 
Example #15
Source File: features.py    From freecad.gears with GNU General Public License v3.0 4 votes vote down vote up
def execute(self, fp):
        fp.gear.double_helix = fp.double_helix
        fp.gear.m_n = fp.module.Value
        fp.gear.z = fp.teeth
        fp.gear.undercut = fp.undercut
        fp.gear.shift = fp.shift
        fp.gear.pressure_angle = fp.pressure_angle.Value * np.pi / 180.
        fp.gear.beta = fp.beta.Value * np.pi / 180
        fp.gear.clearance = fp.clearance
        fp.gear.backlash = fp.backlash.Value * \
            (-fp.reversed_backlash + 0.5) * 2.
        fp.gear.head = fp.head
        # checksbackwardcompatibility:
        if "properties_from_tool" in fp.PropertiesList:
            fp.gear.properties_from_tool = fp.properties_from_tool
        fp.gear._update()
        pts = fp.gear.points(num=fp.numpoints)
        rotated_pts = pts
        rot = rotation(-fp.gear.phipart)
        for i in range(fp.gear.z - 1):
            rotated_pts = list(map(rot, rotated_pts))
            pts.append(np.array([pts[-1][-1], rotated_pts[0][0]]))
            pts += rotated_pts
        pts.append(np.array([pts[-1][-1], pts[0][0]]))
        if not fp.simple:
            wi = []
            for i in pts:
                out = BSplineCurve()
                out.interpolate(list(map(fcvec, i)))
                wi.append(out.toShape())
            wi = Wire(wi)
            if fp.beta.Value == 0:
                sh = Face(wi)
                fp.Shape = sh.extrude(App.Vector(0, 0, fp.height.Value))
            else:
                fp.Shape = helicalextrusion(
                    wi, fp.height.Value, fp.height.Value * np.tan(fp.gear.beta) * 2 / fp.gear.d, fp.double_helix)
        else:
            rw = fp.gear.dw / 2
            fp.Shape = Part.makeCylinder(rw, fp.height.Value)

        # computed properties
        fp.dw = "{}mm".format(fp.gear.dw)
        fp.transverse_pitch = "{}mm".format(fp.gear.pitch)