def hex1(params, document): key = params["key"] d1 = params["d1"] k = params["k"] s = params["s"] h = params["h"] if h is None: h = 0.0 l = params["l"] name = params["name"] part = document.addObject("Part::Feature", name) # head a = s / math.tan(math.pi / 3.0) box1 = makeBox(a, s, k) box1.translate(Vector(-0.5 * a, -0.5 * s, 0)) box1.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 30) box2 = makeBox(a, s, k) box2.translate(Vector(-0.5 * a, -0.5 * s, 0)) box2.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 150) box3 = makeBox(a, s, k) box3.translate(Vector(-0.5 * a, -0.5 * s, 0)) box3.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 270) head = box1.fuse(box2).fuse(box3) shaft_unthreaded = Part.makeCylinder(0.5 * d1, h + k) shaft_threaded = Part.makeCylinder(0.5 * d1, l - h) shaft_threaded.translate(Vector(0, 0, h + k)) part.Shape = head.fuse(shaft_unthreaded).fuse(shaft_threaded).removeSplitter()
def RumbaFanMount(): xsize = 14 ysize = 8 zsize = 40 bb = Part.makeBox(xsize,ysize,zsize) bb=bb.makeFillet(2,[bb.Edges[0],bb.Edges[2],bb.Edges[4],bb.Edges[6]]) bc = Part.makeBox(xsize,ysize,zsize) bc=bc.makeFillet(xsize-0.1,[bc.Edges[3]]) bc.translate(Vector(6,0,10)) bb=bb.cut(bc) bb=bb.makeFillet(2,[bb.Edges[19]]) pin = Part.makeCylinder(0.5,7) pins = pin for i in range(0,5): for j in range(0,2): p = pin.copy() p.translate(Vector(2.54*i,2.54*j,0)) pins=pins.fuse(p) pins.translate(Vector(2,2.5,0)) mh = Part.makeCylinder(1.8,zsize/2) mh.translate(Vector(3,ysize/2,zsize/2)) os = Part.makeCylinder(3.5,zsize) os.translate(Vector(-5,ysize/2,0)) omh = Part.makeCylinder(1.8,zsize/2) omh.translate(Vector(-5,ysize/2,zsize/2)) os=os.cut(omh) rfm = bb.cut(pins.fuse(mh)) rfm = rfm.fuse(os) return rfm
def xStop(): gapmod=2 thick = 12 rc = Part.makeCylinder(bc.gantryRodDia/2+ac.minthick,thick) rc.rotate(Vector(0,0,0),Vector(0,1,0),90) rc.translate(Vector(0,0,ac.xrodspacing/2)) rc = rc.fuse(rc.mirror(Vector(0,0,0),Vector(0,0,1))) bb = Part.makeBox(thick,ac.minthick,ac.xrodspacing) bb.translate(Vector(0,-bc.gantryRodDia/2-ac.minthick,-ac.xrodspacing/2)) es = Part.makeBox(thick,ac.minthick+bc.gantryRodDia,ac.xrodspacing/4) es.translate(Vector(0,-bc.gantryRodDia/2-ac.minthick,-ac.xrodspacing/5)) es = es.makeFillet(ac.minthick,[es.Edges[10],es.Edges[11]]) cs = Part.makeBox(thick,bc.gantryRodDia/2+ac.minthick,bc.gantryRodDia-gapmod) cs.translate(Vector(0,0,-(bc.gantryRodDia-gapmod)/2+ac.xrodspacing/2)) rd = Part.makeCylinder(bc.gantryRodDia/2,thick) rd.rotate(Vector(0,0,0),Vector(0,1,0),90) rd.translate(Vector(0,0,ac.xrodspacing/2)) rd=rd.fuse(cs) rd = rd.fuse(rd.mirror(Vector(0,0,0),Vector(0,0,1))) xs = rc.fuse(bb) xs = xs.makeFillet(bc.gantryRodDia/2-0.01,[xs.Edges[0],xs.Edges[5]]) xs = xs.fuse(es) xs = xs.makeFillet(bc.gantryRodDia/2-0.01,[xs.Edges[24],xs.Edges[60]]) xs = xs.cut(rd) xs = xs.makeFillet(ac.minthick/2,[xs.Edges[73],xs.Edges[74],xs.Edges[107],xs.Edges[111]]) if dc.forPrint == 0: xs.translate(Vector(-ac.xrodlen/2+50,ac.xrodypos,ac.xrodzcenter)) else: xs.rotate(Vector(0,0,0),Vector(0,1,0),90) xs.translate(Vector(0,0,thick)) return xs
def __init__(self, doc, name='regul'): # carte puissance data = { 'r_ext': 30., # mm 'r_int': 15., # mm 'z': 2., # mm } self.data = data col_box = { 'r_ext': 29., # mm 'r_int': 16., # mm 'z': 8., # mm } self.col_box = col_box # make board comp = Part.makeCylinder(data['r_ext'], data['z']) comp = comp.cut(Part.makeCylinder(data['r_int'], data['z'])) comp.translate(Vector(0, 0, -data['z'] / 2)) comp = comp.fuse(comp) # make its collision box box = Part.makeCylinder(col_box['r_ext'], col_box['z']) box = box.cut(Part.makeCylinder(col_box['r_int'], col_box['z'])) box.translate(Vector(0, 0, -col_box['z'] / 2 + 2)) box = box.fuse(comp) ElecComponent.__init__(self, doc, comp, box, name, (0., 0.67, 0.))
def parachute_draw(doc): """every thing related to parachute""" # bottom of parachute case total_len = propulsor.propulsor_data['len'] + rd.case_equipement['len'] total_len += 2 * profiles.bague_data['thick'] + 2 * profiles.disque_data['thick'] obj = Part.makeCylinder(200, 1) obj.translate(Vector(0, 0, total_len)) doc.addObject("Part::Feature", 'bottom_parachute_case').Shape = obj FreeCAD.Gui.ActiveDocument.getObject("bottom_parachute_case").Visibility = False # top of parachute case total_len += rd.case_parachute['len'] total_len += profiles.bague_data['thick'] + profiles.disque_data['thick'] obj = Part.makeCylinder(200, 1) obj.translate(Vector(0, 0, total_len)) doc.addObject("Part::Feature", 'top_parachute_case').Shape = obj FreeCAD.Gui.ActiveDocument.getObject("top_parachute_case").Visibility = False total_len -= parachute.recup_system_data['len'] obj = Part.makeCylinder(200, 1) obj.translate(Vector(0, 0, total_len)) doc.addObject("Part::Feature", 'bottom_recup_system').Shape = obj FreeCAD.Gui.ActiveDocument.getObject("bottom_recup_system").Visibility = False rsd = parachute.recup_system_data for i in range(3): servo = parachute.servo() servo.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 90) servo.rotate(Vector(0, 0, 0), Vector(0, 1, 0), 90) servo.translate(Vector(rsd['servo offset x'], rsd['servo offset y'], total_len + rsd['servo offset z'])) servo.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 60 + 120 * i) doc.addObject("Part::Feature", 'servo %d' % i).Shape = servo
def makeTube(outerRadius, innerRadius, height): outer_cylinder = Part.makeCylinder(outerRadius, height) shape = outer_cylinder if innerRadius > 0 and innerRadius < outerRadius: inner_cylinder = Part.makeCylinder(innerRadius, height) shape = outer_cylinder.cut(inner_cylinder) return shape
def __init__(self, doc, tube, name='aero_clutch'): self.data = { 'len': 20., # mm 'width' : 15., # mm } data = self.data data['thick'] = tube['thick'] # mm data['ext diameter'] = tube['int diameter'] - tube['thick'] # mm data['int diameter'] = tube['int diameter'] - 3 * tube['thick'] # mm # rebuild a tube int_part = Part.makeCylinder(data['int diameter'] / 2, data['len']) ext_part = Part.makeCylinder(data['ext diameter'] / 2, data['len']) part = ext_part.cut(int_part) # cut the external shape shape = Part.makeBox(2 * data['ext diameter'], 2 * data['ext diameter'], data['len']) shape.translate(Vector(-data['ext diameter'], -data['ext diameter'], 0)) comp = part.common(shape) # cut the nerves nerv = Part.makeBox(data['ext diameter'] / 2 - 2 * data['thick'], 3., data['len'] / 2) nerv.translate(Vector(-data['ext diameter'] / 2 + data['thick'] / 2, -3. / 2, 0)) comp = comp.cut(nerv) MecaComponent.__init__(self, doc, comp, name, (1., 1., 0.))
def hex2(params,document): key = params['key'] d1 = params['d1'] k = params['k'] s = params['s'] b1 = params['b1'] b2 = params['b2'] b3 = params['b3'] l = params['l'] b = b3; if l < 125: b = b1 elif l < 200: b = b2 name = params['name'] part = document.addObject("Part::Feature",name) #head a = s/math.tan(math.pi/3.) box1 = makeBox(a,s,k) box1.translate(Vector(-0.5*a,-0.5*s,0)) box1.rotate(Vector(0,0,0),Vector(0,0,1),30) box2 = makeBox(a,s,k) box2.translate(Vector(-0.5*a,-0.5*s,0)) box2.rotate(Vector(0,0,0),Vector(0,0,1),150) box3 = makeBox(a,s,k) box3.translate(Vector(-0.5*a,-0.5*s,0)) box3.rotate(Vector(0,0,0),Vector(0,0,1),270) head = box1.fuse(box2).fuse(box3) shaft_unthreaded = Part.makeCylinder(0.5*d1,l-b+k) shaft_threaded = Part.makeCylinder(0.5*d1,b) shaft_threaded.translate(Vector(0,0,l-b+k)) part.Shape = head.fuse(shaft_unthreaded).fuse(shaft_threaded)
def flange(d1,k,D,b,d2,bn,blind,part): ## flange disk p0 = Base.Vector(0.,0.,0.) caxis = Base.Vector(0.,0.,1) disk = Part.makeCylinder(0.5 * D,b,p0,caxis) # if not a blind flange, make the inner hole. if not blind: hole = Part.makeCylinder(0.5 * d1,b,p0,caxis) disk = disk.cut(hole).removeSplitter() ## bolts holes h0 = Base.Vector(0.5 * k,0.,0.) hole = Part.makeCylinder(0.5 * d2,b,h0,caxis) holes = hole.copy() for i in range(1,int(bn)): nhole = hole.copy() nhole.rotate(p0,caxis,i * 360. / bn) holes = holes.fuse(nhole) # drill holes flange = disk.cut(holes).removeSplitter() ## chamfer all edges part.Shape = flange.makeChamfer(0.05 * b,flange.Edges)
def ExtruderIdler(): bb = Part.makeBox(15,11,36) lp = Part.makeCylinder(11/2,12) lp.rotate(Vector(0,0,0),Vector(0,1,0),90) lp.translate(Vector(0,11/2,0)) #pivot clearance pc = Part.makeCylinder(11/2,12) pcb = Part.makeBox(12,24,12) pcb.translate(Vector(0,-12,0)) pc = pc.fuse(pcb) pc = pc.makeFillet(5,[pc.Edges[18],pc.Edges[20]]) pc.rotate(Vector(0,0,0),Vector(0,1,0),90) pc.translate(Vector(12,11/2,0)) #bs bs = Part.makeCylinder(11/2,15) bs.rotate(Vector(0,0,0),Vector(0,1,0),90) bs.translate(Vector(0,21-ps.z624[1]/2-filamentDia/2-gearDia/2,15.5)) bb=bb.fuse(lp) bb=bb.cut(pc) bb=bb.fuse(bs) bb.translate(Vector(-8,-21,-15.5)) ei = bb return ei
def hex2(params, document): key = params["key"] d1 = params["d1"] k = params["k"] s = params["s"] b1 = params["b1"] b2 = params["b2"] b3 = params["b3"] l = params["l"] b = b3 if l < 125: b = b1 elif l < 200: b = b2 name = params["name"] part = document.addObject("Part::Feature", name) # head a = s / math.tan(math.pi / 3.0) box1 = makeBox(a, s, k) box1.translate(Vector(-0.5 * a, -0.5 * s, 0)) box1.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 30) box2 = makeBox(a, s, k) box2.translate(Vector(-0.5 * a, -0.5 * s, 0)) box2.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 150) box3 = makeBox(a, s, k) box3.translate(Vector(-0.5 * a, -0.5 * s, 0)) box3.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 270) head = box1.fuse(box2).fuse(box3) shaft_unthreaded = Part.makeCylinder(0.5 * d1, l - b + k) shaft_threaded = Part.makeCylinder(0.5 * d1, b) shaft_threaded.translate(Vector(0, 0, l - b + k)) part.Shape = head.fuse(shaft_unthreaded).fuse(shaft_threaded).removeSplitter()
def FilletFlange(innerdia = 10,filletdia = 5,filletthick=10): ff = Part.makeCylinder(innerdia/2 + filletdia/2,filletthick) fi = Part.makeCylinder(innerdia/2,filletthick+filletdia) fi.translate(Vector(0,0,-filletdia/2)) ff=ff.fuse(fi) ff=ff.fuse(ff.makeFillet(filletdia/2-0.01,[ff.Edges[3],ff.Edges[5]])) return ff
def MakeDehousing(self): self.debase=Part.makeCylinder(self.debasecylinderradius, self.debasecylinderlength, self.origin+FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(1,0,0), 360) self.desphere=Part.makeSphere(self.desphereradius, self.origin+FreeCAD.Vector(self.despherexshift,0,0), FreeCAD.Vector(1,0,0), self.desphereangle, 90, 360) self.debase=self.debase.fuse(self.desphere) self.debox=Part.makeBox(self.deboxwidth, self.deboxlength, self.deboxheight, self.origin+FreeCAD.Vector(3, -self.deboxlength / 2, self.deboxzshift), FreeCAD.Vector(0,0,1)) self.debox=self.debox.makeFillet(self.deboxlength/2 - 0.5, [self.debox.Edges[4],self.debox.Edges[6]]) self.decone=Part.makeCone(self.deboxlength/2 , self.decylinderradius, self.deconelength, self.origin+FreeCAD.Vector(self.deaxisxshift, 0, self.deboxheight + self.deboxzshift), FreeCAD.Vector(0,0,1), 310) self.decone.rotate(self.origin+FreeCAD.Vector(self.deaxisxshift, 0, self.deboxheight + self.deboxzshift), FreeCAD.Vector(0,0,1), -155) self.debox=self.debox.fuse(self.decone) self.decylinder=Part.makeCylinder(self.decylinderradius, self.decylinderlength, self.origin+FreeCAD.Vector(self.deaxisxshift, 0, self.deboxheight + self.deboxzshift + self.deconelength), FreeCAD.Vector(0,0,1), 360) #self.decylinder=self.decylinder.fuse(self.decone) self.dehousing=self.debase.fuse(self.debox) self.dehousing=self.dehousing.fuse(self.decylinder) self.dehousing=self.dehousing.cut(Part.makeCylinder(self.deaxisradius, self.deboxheight+self.deconelength+self.decylinderlength, self.origin+FreeCAD.Vector(self.deaxisxshift, 0, self.deboxzshift), FreeCAD.Vector(0,0,1), 360)) self.shape=self.dehousing return self.shape
def hex1(params,document): key = params['key'] d1 = params['d1'] k = params['k'] s = params['s'] h = params['h'] if h is None: h = 0. l = params['l'] name = params['name'] part = document.addObject("Part::Feature",name) #head a = s/math.tan(math.pi/3.) box1 = makeBox(a,s,k) box1.translate(Vector(-0.5*a,-0.5*s,0)) box1.rotate(Vector(0,0,0),Vector(0,0,1),30) box2 = makeBox(a,s,k) box2.translate(Vector(-0.5*a,-0.5*s,0)) box2.rotate(Vector(0,0,0),Vector(0,0,1),150) box3 = makeBox(a,s,k) box3.translate(Vector(-0.5*a,-0.5*s,0)) box3.rotate(Vector(0,0,0),Vector(0,0,1),270) head = box1.fuse(box2).fuse(box3) shaft_unthreaded = Part.makeCylinder(0.5*d1,h+k) shaft_threaded = Part.makeCylinder(0.5*d1,l-h) shaft_threaded.translate(Vector(0,0,h+k)) part.Shape = head.fuse(shaft_unthreaded).fuse(shaft_threaded)
def axialthrustbearing(params, document): rin_w = 0.5*params['d_w'] rin_g = 0.5*params['d_g'] rout_w = 0.5*params['D_w'] rout_g = 0.5*params['D_g'] r_fillet = params['r_fillet'] bth = params['T'] name = params['name'] fth=0.3*bth #Thrust plate widh shapes=[] #Lower ring lr1=Part.makeCylinder(rout_g,fth) lr2=Part.makeCylinder(rin_g,fth) lr=lr1.cut(lr2) lre=lr.Edges lr=lr.makeFillet(r_fillet,lre) #Upper ring ur1=Part.makeCylinder(rout_w,fth) ur2=Part.makeCylinder(rin_w,fth) ur=ur1.cut(ur2) ure=ur.Edges ur=ur.makeFillet(r_fillet,ure) #Positioning Vector Vur=(0,0,bth-fth) ur.translate(Vur) #Balltracks tbigradius=((rout_w-rin_g)/2.00)+rin_g tsmradius=(bth/2.00)-(0.75*fth) Vtorus=(0,0,bth/2.00) torus=makeRing(tbigradius,tsmradius) #Positioning vector torus.translate(Vtorus) #Booleans lr=lr.cut(torus) ur=ur.cut(torus) shapes.append(ur) shapes.append(lr) #Balls RBall=tsmradius CBall=tbigradius #Ball number (constant multiplied by radius and rounded) NBall=(2*math.pi*CBall)/(2*RBall) NBall=math.floor(NBall) NBall=NBall*0.9 NBall=int(NBall) #Ball creator for i in range (NBall): Ball=Part.makeSphere(RBall) Alpha=(i*2*math.pi)/NBall BV=(CBall*math.cos(Alpha),CBall*math.sin(Alpha),bth/2.00) Ball.translate(BV) shapes.append(Ball) part = document.addObject("Part::Feature","BOLTS_part") comp = Part.Compound(shapes) part.Shape = comp.removeSplitter() part.Label = name
def carte_regul(): """carte regulation""" # make carte comp = Part.makeCylinder(carte_regul_data['r_ext'], carte_regul_data['z']) comp = comp.cut(Part.makeCylinder(carte_regul_data['r_int'], carte_regul_data['z'])) return comp
def Fan(size=40,thick=10.75,screwdia=3.25,screwspacing=32): fb = Part.makeBox(size,thick,size) fb = fb.makeFillet(screwdia,[fb.Edges[1],fb.Edges[3],fb.Edges[5],fb.Edges[7]]) #port pt = Part.makeCylinder(size/2-(size*0.02),thick) pt.rotate(Vector(0,0,0),Vector(1,0,0),-90) pt.translate(Vector(size/2,0,size/2)) #screws sc = Part.makeCylinder(screwdia/2,thick) sc.rotate(Vector(0,0,0),Vector(1,0,0),-90) sc.translate(Vector(size/2,0,size/2)) s1=sc.copy() s1.translate(Vector(-screwspacing/2,0,-screwspacing/2)) s2=sc.copy() s2.translate(Vector(-screwspacing/2,0,screwspacing/2)) s3=sc.copy() s3.translate(Vector(screwspacing/2,0,screwspacing/2)) s4=sc.copy() s4.translate(Vector(screwspacing/2,0,-screwspacing/2)) sc=s1.fuse(s2.fuse(s3).fuse(s4)) #fanhub fh = Part.makeCylinder(size/4,thick) fh.rotate(Vector(0,0,0),Vector(1,0,0),-90) fh.translate(Vector(size/2,0,size/2)) #fan blades n = 7 bth = 1 bl = Part.makeBox(bth,thick*2,size/2) bl.translate(Vector(-bth/2,-thick,0)) bl.rotate(Vector(0,0,0),Vector(0,0,1),-45) bl.translate(Vector(size/2,thick/2,size/2)) bls = bl.copy() for i in range(1,n): b=bl.copy() b.rotate(Vector(size/2,0,size/2),Vector(0,1,0),(360/n)*i) bls=bls.fuse(b) blsfc = Part.makeBox(size+20,thick,size+20) blsfc.translate(Vector(-10,-thick+2,-10)) bls = bls.cut(blsfc) blsfc.translate(Vector(0,thick*2-4,0)) bls = bls.cut(blsfc) blset = Part.makeCylinder(size/2-(size*0.016),thick) blset.rotate(Vector(0,0,0),Vector(1,0,0),-90) blset.translate(Vector(size/2,0,size/2)) bls = bls.common(blset) fan = fb.cut(pt) fan = fan.cut(sc) fan = fan.fuse(fh) fan = fan.fuse(bls) return fan
def NemaMotor(motor=[]): bodyblank = Part.makeBox(motor[0], motor[0], motor[1]) body = bodyblank.makeChamfer(motor[0]/12, [bodyblank.Edges[0], bodyblank.Edges[2], bodyblank.Edges[4], bodyblank.Edges[6]]) body.translate(Vector(-motor[0]/2, -motor[0]/2, -motor[1])) face = Part.makeCylinder(motor[5]/2, 2) shaft = Part.makeCylinder(motor[2]/2, motor[3]) fuse1 = face.fuse(shaft) motor = body.fuse(fuse1) return motor
def addStandoffs(self, part, height, ID, OD, points): for point in points: if type(point) is tuple or type(point) is list: point = Base.Vector(point[0], point[1], point[2]) post = Part.makeCylinder(OD/2.0, height, point) part = part.fuse(post) screwhole = Part.makeCylinder(ID/2.0, height, point) part = part.cut(screwhole) return part
def roundBattery(params,document): diam = params['d'] h = params['h'] name = params['name'] part = document.addObject("Part::Feature",name) nub = Part.makeCylinder(0.15*diam,h) cell = Part.makeCylinder(0.5*diam,0.97*h) part.Shape = nub.fuse(cell).removeSplitter()
def singlerowradialbearing(params,document): rout=0.5*params['d2'] rin=0.5*params['d1'] bth=0.5*params['B'] r_fillet=0.5*params['r_fillet'] name=params['name'] seal = params['type'] #shapes shapes=[] RR=0.015*rout rb=(rout-rin)*0.25 cb=((rout-rin)/2.00+rin) #outer ring our=Part.makeCylinder(rout,bth).cut(Part.makeCylinder(cb+rb*0.7,bth)) our=our.makeFillet(r_fillet,our.Edges) #inner ring inr=Part.makeCylinder(cb-rb*0.7,bth).cut(Part.makeCylinder(rin,bth)) inr=inr.makeFillet(r_fillet,inr.Edges) if seal == "open" or seal.endswith("single"): #track t=Part.makeCylinder(cb+rb,2*0.7*rb).cut(Part.makeCylinder(cb-rb,2*0.7*rb)) t.translate((0,0,0.5*0.7*rb)) our=our.cut(t) inr=inr.cut(t) shapes.append(our) shapes.append(inr) #Balls nb=int(math.floor(math.pi*cb*0.8/rb)) for i in range (nb): b=Part.makeSphere(rb) Alpha=(i*2*math.pi)/nb bv=(cb*math.cos(Alpha),cb*math.sin(Alpha),bth/2) b.translate(bv) shapes.append(b) if seal.endswith("single"): #seal one side sl=Part.makeCylinder(cb+rb*0.9,0.5*bth-RR).cut(Part.makeCylinder(cb-rb*0.9,0.5*bth-RR)) sl.translate((0,0,0.5*bth+RR)) shapes.append(sl) elif seal.endswith("double"): shapes.append(our) shapes.append(inr) #seal sl=Part.makeCylinder(cb+rb*0.9,bth-2*RR).cut(Part.makeCylinder(cb-rb*0.9,bth-2*RR)) sl.translate((0,0,RR)) shapes.append(sl) part = document.addObject("Part::Feature","BOLTS_part") comp=Part.Compound(shapes) part.Shape=comp.removeSplitter() part.Label = name
def __init__(self, doc, name='cone'): self.data = { 'len lo': 70., # mm 'len up': 120., # mm 'int diameter': 36., # mm 'thick': 1., # mm } int_diam = self.data['int diameter'] len_up = self.data['len up'] len_lo = self.data['len lo'] ext_diam = int_diam + 2 * self.data['thick'] int_cone = Part.makeSphere(int_diam / 2) ext_cone = Part.makeSphere(ext_diam / 2) box = Part.makeBox(ext_diam, ext_diam, ext_diam) box.translate(Vector(-ext_diam / 2, -ext_diam / 2, 0)) cone_up = ext_cone.cut(int_cone) cone_up = cone_up.common(box) matrix = Matrix() matrix.scale(1., 1., len_up / (ext_diam / 2)) cone_up = cone_up.transformGeometry(matrix) cone_up.translate(Vector(0, 0, len_lo)) cone_up = cone_up.fuse(cone_up) # blocking thread (pas de vis de blocage) # radius = self.data['int diameter'] / 2 # # helix = Part.makeHelix(4., 20., radius) # # p0 = (radius, 0, 0) # p1 = (radius, 0, 3) # p2 = (radius - 1, 0, 2) # p3 = (radius - 1, 0, 1) # # e0 = Part.makeLine(p0, p1) # e1 = Part.makeLine(p1, p2) # e2 = Part.makeLine(p2, p3) # e3 = Part.makeLine(p3, p0) # section = Part.Wire([e0, e1, e2, e3]) # helix = Part.Wire(helix).makePipeShell([section], 1, 1) # helix.translate(Vector(0, 0, len_lo - 20)) int_tube = Part.makeCylinder(int_diam / 2, len_lo) ext_tube = Part.makeCylinder(ext_diam / 2, len_lo) cone_lo = ext_tube.cut(int_tube) # cone_lo = cone_lo.fuse(helix) #comp = cone_up.fuse(cone_lo) # BUG: this fusion fails!!! comp = cone_lo MecaComponent.__init__(self, doc, comp, name, (1., 1., 0.))
def pipe(params,document): id = params['id'] od = params['od'] l = params['l'] name = params['name'] part = document.addObject("Part::Feature",name) outer = Part.makeCylinder(0.5*od,l) inner = Part.makeCylinder(0.5*id,l) part.Shape = outer.cut(inner).removeSplitter()
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
def washer1(params,document): key = params['key'] d1 = params['d1'] d2 = params['d2'] s = params['s'] name = params['name'] part = document.addObject("Part::Feature",name) outer = Part.makeCylinder(0.5*d2,s) inner = Part.makeCylinder(0.5*d1,s) part.Shape = outer.cut(inner).removeSplitter()
def axialthrustbearing(params, document): rin = 0.5*params['d'] rout = 0.5*params['D'] bth = params['T'] name = params['name'] fth=0.3*bth #Thrust plate widh RR=0.015*rout #shapes-- shapes=[] #Lower ring-------------------------- lr1=Part.makeCylinder(rout,fth) lr2=Part.makeCylinder(rin,fth) lr=lr1.cut(lr2) lre=lr.Edges lr=lr.makeFillet(RR,lre) #Upper ring-------------------------- ur1=Part.makeCylinder(rout,fth) ur2=Part.makeCylinder(rin,fth) ur=ur1.cut(ur2) ure=ur.Edges ur=ur.makeFillet(RR,ure) #Positioning Vector Vur=(0,0,bth-fth) ur.translate(Vur) #Balltracks--------------------------- tbigradius=((rout-rin)/2.00)+rin tsmradius=(bth/2.00)-(0.75*fth) Vtorus=(0,0,bth/2.00) torus=Part.makeTorus(tbigradius,tsmradius) #Positioning vector torus.translate(Vtorus) #Booleans------------------------------ lr=lr.cut(torus) shapes.append(ur) shapes.append(lr) #Balls-------------------------------- RBall=tsmradius CBall=tbigradius #Ball number (constant multiplied by radius and rounded) NBall=(2*math.pi*CBall)/(2*RBall) NBall=math.floor(NBall) NBall=NBall*0.9 NBall=int(NBall) #Ball creator for i in range (NBall): Ball=Part.makeSphere(RBall) Alpha=(i*2*math.pi)/NBall BV=(CBall*math.cos(Alpha),CBall*math.sin(Alpha),bth/2.00) Ball.translate(BV) shapes.append(Ball) part = document.addObject("Part::Feature",name) comp = Part.Compound(shapes) part.Shape = comp.removeSplitter()
def guide(): """guide""" prop = propulsor_data # make the guide propu = Part.makeCylinder(prop['diameter'] / 2, prop['len']) obj = Part.makeCylinder(prop['diameter'] / 2 + guide_data['thick'], prop['len']) obj = obj.cut(propu) return obj
def TimingGear(pitchdia=25, gearwidth=12, boredia=5,hubdia = 20, hubheight = 6): g = Part.makeCylinder(pitchdia/2, gearwidth) hb = Part.makeCylinder(hubdia/2, hubheight) hb.translate(Vector(0, 0, -hubheight)) f1 = g.fuse(hb) b = Part.makeCylinder(boredia/2, gearwidth + hubheight) b.translate(Vector(0, 0, -hubheight)) c1 = f1.cut(b) c1.translate(Vector(0,0,-gearwidth/2)) tg = c1 return tg
def CapHeadScrew(l=10,d=3,hd=6,hh=3,cut=0): s = Part.makeCylinder(d/2,l) s.translate(Vector(0,0,-l)) if cut == 0: h = Part.makeCylinder(hd/2,hh) if cut == 1: h = Part.makeCylinder(hd/2,hh+hd+l) h = h.makeFillet(hd/2-0.01,[h.Edges[0]]) screw=s.fuse(h) return screw
def MakeCrayford(self): self.crayfordcylinder=Part.makeCylinder(self.crayfordcylinderradius, self.crayfordcylinderlength, self.origin+FreeCAD.Vector(self.crayfordcylinderxshift, 0, 0), FreeCAD.Vector(1,0,0)) self.crayfordcone=Part.makeCone(self.crayfordconeradius,self.crayfordcylinderradius, self.crayfordconelength, self.origin, FreeCAD.Vector(-1,0,0)) self.crayfordcylinder=self.crayfordcylinder.fuse(self.crayfordcone) self.crayfordbox=Part.makeBox(self.crayfordboxsize, 2*self.crayfordcylinderradius, self.crayfordboxsize, self.origin + FreeCAD.Vector(self.crayfordboxxshift, -self.crayfordcylinderradius, -self.crayfordcylinderradius), FreeCAD.Vector(0,0,1)) self.crayfordbox=self.crayfordbox.fuse( Part.makeCylinder(self.crayfordaxisradius, self.crayfordaxislength, self.origin + FreeCAD.Vector(self.crayfordboxxshift+self.crayfordboxsize/2, -self.crayfordaxislength/2, -self.crayfordcylinderradius+self.crayfordboxsize/2), FreeCAD.Vector(0,1,0))) self.crayfordbox=self.crayfordbox.fuse( Part.makeCylinder(self.crayfordwheelradius, self.crayfordwheellength, self.origin + FreeCAD.Vector(self.crayfordboxxshift+self.crayfordboxsize/2, -self.crayfordaxislength/2, -self.crayfordcylinderradius+self.crayfordboxsize/2), FreeCAD.Vector(0,1,0))) self.crayfordbox=self.crayfordbox.fuse( Part.makeCylinder(self.crayfordwheelradius, self.crayfordwheellength, self.origin + FreeCAD.Vector(self.crayfordboxxshift+self.crayfordboxsize/2, self.crayfordaxislength/2-(self.crayfordwheellength), -self.crayfordcylinderradius+self.crayfordboxsize/2), FreeCAD.Vector(0,1,0))) self.crayfordcylinder=self.crayfordcylinder.fuse(self.crayfordbox) self.crayfordcylinder=self.crayfordcylinder.cut( Part.makeCylinder(self.crayfordcylinderinnerradius, self.crayfordcylinderlength, self.origin+FreeCAD.Vector(self.crayfordcylinderxshift, 0, 0), FreeCAD.Vector(1,0,0))) self.crayfordspacer=Part.makeCylinder(self.tubespacerradius, self.tubespacerlength, self.origin, FreeCAD.Vector(1,0,0)) self.crayfordspacer=self.crayfordspacer.cut( Part.makeCylinder(self.crayfordcylinderradius, self.tubespacerlength, self.origin, FreeCAD.Vector(1,0,0))) self.crayfordtube=Part.makeCylinder(self.crayfordtuberadius, self.crayfordtubelength, self.origin+FreeCAD.Vector(self.crayfordcylinderxshift+self.crayfordtubexshiftmin, 0, 0), FreeCAD.Vector(1,0,0)) self.crayfordtube=self.crayfordtube.cut( Part.makeCylinder(self.crayfordtubeinnerradius, self.crayfordtubelength, self.origin+FreeCAD.Vector(self.crayfordcylinderxshift+self.crayfordtubexshiftmin, 0, 0), FreeCAD.Vector(1,0,0))) self.crayford=self.crayfordcylinder.fuse(self.crayfordspacer) self.crayford=self.crayford.fuse(self.crayfordtube) self.shape=self.crayford return self.shape
def buildcylens(CS1, CS2, W, H, CT): d = Part.makeBox(H, W, CT + H) d.translate(FreeCAD.Base.Vector(-H / 2.0, -W / 2, -(CT + H) / 2)) if CS1 == 0: R1 = 1e6 else: R1 = 1.0 / CS1 f1 = Part.makeCylinder( abs(R1), W, FreeCAD.Base.Vector(0, -W / 2, 0), FreeCAD.Base.Vector(0, 1, 0), ) f1.translate(FreeCAD.Base.Vector(0, 0, R1 - CT / 2)) if CS2 == 0: R2 = 1e6 else: R2 = 1.0 / CS2 f2 = Part.makeCylinder( abs(R2), W, FreeCAD.Base.Vector(0, -W / 2, 0), FreeCAD.Base.Vector(0, 1, 0), ) f2.translate(FreeCAD.Base.Vector(0, 0, R2 + CT / 2)) if R1 > 0: t = d.common(f1) else: t = d.cut(f1) if R2 > 0: t = t.cut(f2) else: t = t.common(f2) return t
def needlebearing(params, document): rout = 0.5 * params["Ew"] rin = 0.5 * params["Fw"] bth = params["Bc"] name = params['name'] rnd = (rout - rin) / 2.00 cnd = ((rout - rin) / 2) + rin #Needle number nnd = 2 * math.pi * cnd / (1.8 * 2 * rnd) nnd = int(math.floor(nnd)) shapes = [] #needle cage ncrout = cnd + 0.175 * (rout - rin) ncrin = cnd - 0.175 * (rout - rin) nc1 = Part.makeCylinder(ncrout, bth) nc2 = Part.makeCylinder(ncrin, bth) nc = nc1.cut(nc2) #needle space on the cage- rsnd = rnd * 1.2 thsnd = bth * 0.8 for i in range(nnd): snd = Part.makeCylinder(rsnd, thsnd) Alpha = (i * 2 * math.pi) / nnd nv = (cnd * math.cos(Alpha), cnd * math.sin(Alpha), 0.1 * bth) snd.translate(nv) nc = nc.cut(snd) #Needle creation for i in range(nnd): nd = Part.makeCylinder(rnd, thsnd) Alpha = (i * 2 * math.pi) / nnd nv = (cnd * math.cos(Alpha), cnd * math.sin(Alpha), 0.1 * bth) nd.translate(nv) shapes.append(nd) shapes.append(nc) part = document.addObject("Part::Feature", "BOLTS_part") comp = Part.Compound(shapes) part.Shape = comp.removeSplitter() part.Label = name
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()]
def process(self): if not any(socket.is_linked for socket in self.outputs): return params = [s.sv_get()[0] for s in self.inputs] solids = [] for rad, height, origin, direc, angle in zip(*mlr(params)): cylinder = Part.makeCylinder(rad, height, Base.Vector(origin), Base.Vector(direc), angle) solids.append(cylinder) self.outputs['Solid'].sv_set(solids)
def setupUi(self): # setup the form fields self.setFields() # build the tool representation if self.form.txtToolDiameter.text() != "UNDEFINED": radius = float(self.form.txtToolDiameter.text()) / 2 length = radius * 8 t = Part.makeCylinder(radius, length) self.toolrep = FreeCAD.ActiveDocument.addObject( "Part::Feature", "tool") self.toolrep.Shape = t
def mirrorShape(mirror): '''Computes the 3D representation of the mirror, a shape for a CAD file obj. beam: beam to represent. [GaussianBeam] Returns a shape for a CAD file object. ''' fact = settings.FCFactor #factor for units in CAD return Part.makeCylinder((mirror.Dia / 2.) / fact, mirror.Thick / fact, Base.Vector(0, 0, 0), Base.Vector(tuple(-mirror.HRNorm)))
def __init__(self, proxy, z, R): self.proxy = proxy self.z = z self.toolRadius = R self.angle = math.fabs(proxy.obj.Angle) self.width = math.fabs(proxy.obj.Width) self.height = math.fabs(proxy.obj.Height) self.radius = math.fabs(proxy.obj.Radius) self.actualHeight = self.height self.fullWidth = 2 * self.toolRadius + self.width r1 = self.fullWidth / 2 self.r1 = r1 self.r2 = r1 height = self.actualHeight * 1.01 radius = 0 if self.angle == 90 and height > 0: # cylinder self.solid = Part.makeCylinder(r1, height) radius = min(min(self.radius, r1), self.height) PathLog.debug("Part.makeCylinder(%f, %f)" % (r1, height)) elif self.angle > 0.0 and height > 0.0: # cone rad = math.radians(self.angle) tangens = math.tan(rad) dr = height / tangens if dr < r1: # with top r2 = r1 - dr s = height / math.sin(rad) radius = min(r2, s) * math.tan((math.pi - rad)/2) * 0.95 else: # triangular r2 = 0 height = r1 * tangens * 1.01 self.actualHeight = height self.r2 = r2 PathLog.debug("Part.makeCone(r1=%.2f, r2=%.2f, h=%.2f)" % (r1, r2, height)) self.solid = Part.makeCone(r1, r2, height) else: # degenerated case - no tag PathLog.debug("Part.makeSphere(%.2f)" % (r1 / 10000)) self.solid = Part.makeSphere(r1 / 10000) radius = min(self.radius, radius) self.realRadius = radius if radius != 0: PathLog.debug("makeFillet(%.4f)" % radius) self.solid = self.solid.makeFillet(radius, [self.solid.Edges[0]]) #lastly determine the center of the model, we want to make sure the seam of # the tag solid points away (in the hopes it doesn't coincide with a path) self.baseCenter = FreeCAD.Vector((proxy.ptMin.x+proxy.ptMax.x)/2, (proxy.ptMin.y+proxy.ptMax.y)/2, 0)
def beamDumpShape(beamDump): '''Computes the 3D representation of the beamdump, for a CAD file obj. beam: beam to represent. [GaussianBeam] Returns a shape for a CAD file object. ''' fact = settings.FCFactor #factor for units in CAD return Part.makeCylinder((beamDump.Dia / 2.) / fact, beamDump.Thick / fact, Base.Vector(0, 0, 0), Base.Vector(tuple(-beamDump.HRNorm)))
def Display(scannerPart, showLight=False, showCamera=False): p1 = scannerPart.AbsoluteOffset() uc = Part.makeCylinder(0.2, 50, FreeCADv(p1), FreeCADv(scannerPart.u), 360) DisplayShape(uc, (1.0, 0.0, 0.0)) vc = Part.makeCylinder(0.2, 50, FreeCADv(p1), FreeCADv(scannerPart.v), 360) DisplayShape(vc, (0.0, 1.0, 0.0)) wc = Part.makeCylinder(0.2, 50, FreeCADv(p1), FreeCADv(scannerPart.w), 360) DisplayShape(wc, (0.0, 0.0, 1.0)) # Light source - display the light sheet if scannerPart.lightAngle > 0 and showLight: vv = scannerPart.v ww = scannerPart.w vv = vv.Multiply(veryLong * maths.sin(scannerPart.lightAngle * 0.5)) ww = ww.Multiply(veryLong * maths.cos(scannerPart.lightAngle * 0.5)) p2 = p1.Add(vv).Add(ww) p3 = p1.Sub(vv).Add(ww) e1 = Part.makeLine(FreeCADv(p1), FreeCADv(p2)) e2 = Part.makeLine(FreeCADv(p2), FreeCADv(p3)) e3 = Part.makeLine(FreeCADv(p3), FreeCADv(p1)) DisplayShape(Part.Wire([e1, e2, e3]), (0.5, 0.0, 0.0)) # Camera - display the view pyramid if scannerPart.focalLength > 0 and showCamera: for u in (-1, 1): for v in (-1, 1): ray = scannerPart.GetCameraRay( (scannerPart.uMM * 0.5 * u, scannerPart.vMM * 0.5 * v)) DisplayCameraRay(ray) if scannerPart.parent is not None: p0 = scannerPart.parent.AbsoluteOffset() else: p0 = Vector3(0, 0, 0) twig = Cylinder(p0, p1, 0.1) DisplayShape(twig, (1.0, 1.0, 0.0)) for child in scannerPart.children: Display(child, showLight, showCamera)
def hex2(params, document): # key = params['key'] # not used d1 = params["d1"] k = params["k"] s = params["s"] b1 = params["b1"] b2 = params["b2"] b3 = params["b3"] le = params["l"] b = b3 if le < 125: b = b1 elif le < 200: b = b2 name = params["name"] part = document.addObject("Part::Feature", "BOLTS_part") part.Label = name # head a = s / math.tan(math.pi / 3.0) box1 = makeBox(a, s, k) box1.translate(Vector(-0.5 * a, -0.5 * s, 0)) box1.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 30) box2 = makeBox(a, s, k) box2.translate(Vector(-0.5 * a, -0.5 * s, 0)) box2.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 150) box3 = makeBox(a, s, k) box3.translate(Vector(-0.5 * a, -0.5 * s, 0)) box3.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 270) head = box1.fuse(box2).fuse(box3) shaft_unthreaded = Part.makeCylinder(0.5 * d1, le - b + k) shaft_threaded = Part.makeCylinder(0.5 * d1, b) shaft_threaded.translate(Vector(0, 0, le - b + k)) part.Shape = head.fuse(shaft_unthreaded).removeSplitter().fuse( shaft_threaded) # color thread color_face(part, 9)
def Display(self, showLight=False, showCamera=False): p1 = self.AbsoluteOffset() uc = Part.makeCylinder(0.2, 5, p1, self.u, 360) DisplayShape(uc, (1.0, 0.0, 0.0)) vc = Part.makeCylinder(0.2, 5, p1, self.v, 360) DisplayShape(vc, (0.0, 1.0, 0.0)) wc = Part.makeCylinder(0.2, 5, p1, self.w, 360) DisplayShape(wc, (0.0, 0.0, 1.0)) # Light source - display the light sheet if self.lightAngle > 0 and showLight: vv = copy.deepcopy(self.v) ww = copy.deepcopy(self.w) vv.multiply(veryLong * math.sin(self.lightAngle * 0.5)) ww.multiply(veryLong * math.cos(self.lightAngle * 0.5)) p2 = p1.add(vv).add(ww) p3 = p1.sub(vv).add(ww) e1 = Part.makeLine(p1, p2) e2 = Part.makeLine(p2, p3) e3 = Part.makeLine(p3, p1) DisplayShape(Part.Wire([e1, e2, e3]), (0.5, 0.0, 0.0)) # Camera - display the view pyramid if self.focalLength > 0 and showCamera: for u in (-1, 1): for v in (-1, 1): ray = self.GetCameraRay(self.uMM * 0.5 * u, self.vMM * 0.5 * v) self.DisplayCameraRay(ray) if self.parent is not None: p0 = self.parent.AbsoluteOffset() else: p0 = Base.Vector(0, 0, 0) twig = Cylinder(p0, p1, 0.1) DisplayShape(twig, (1.0, 1.0, 0.0)) for child in self.children: child.Display(showLight, showCamera)
def createInnerPart(cls, obj): dims = cls.extractDimensions(obj) aux = dims.calculateAuxiliararyPoints() p1 = aux["p1"] p3 = aux["p3"] p4 = aux["p4"] p6 = aux["p6"] pid = dims.PID() pid1 = dims.PID1() pod = dims.POD pod1 = dims.POD1 hr = pid / 2 hor_cylinder = Part.makeCylinder( hr, dims.L, p1, FreeCAD.Vector(1, 0, 0)) vr = pid1 / 2 vert_cylinder = Part.makeCylinder(vr, dims.L1, p4) # Create sockets. socket_left = Part.makeCylinder( pod / 2, dims.socketDepthLeft(), p1, FreeCAD.Vector(1, 0, 0)) socket_right = Part.makeCylinder( pod / 2, dims.socketDepthRight(), p3, FreeCAD.Vector(1, 0, 0)) socket_bottom = Part.makeCylinder( pod1 / 2, dims.socketDepthBottom(), p4) socket_top = Part.makeCylinder(pod1 / 2, dims.socketDepthTop(), p6) # Combine all cylinders. inner = hor_cylinder.fuse([vert_cylinder, socket_left, socket_right, socket_bottom, socket_top]) return inner
def hex2(params, document): key = params['key'] d1 = params['d1'] k = params['k'] s = params['s'] b1 = params['b1'] b2 = params['b2'] b3 = params['b3'] l = params['l'] b = b3 if l < 125: b = b1 elif l < 200: b = b2 name = params['name'] part = document.addObject("Part::Feature", "BOLTS_part") part.Label = name #head a = s / math.tan(math.pi / 3.) box1 = makeBox(a, s, k) box1.translate(Vector(-0.5 * a, -0.5 * s, 0)) box1.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 30) box2 = makeBox(a, s, k) box2.translate(Vector(-0.5 * a, -0.5 * s, 0)) box2.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 150) box3 = makeBox(a, s, k) box3.translate(Vector(-0.5 * a, -0.5 * s, 0)) box3.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 270) head = box1.fuse(box2).fuse(box3) shaft_unthreaded = Part.makeCylinder(0.5 * d1, l - b + k) shaft_threaded = Part.makeCylinder(0.5 * d1, b) shaft_threaded.translate(Vector(0, 0, l - b + k)) part.Shape = head.fuse(shaft_unthreaded).removeSplitter().fuse( shaft_threaded) #color thread color_face(part, 9)
def execute(self, fp): super(InvoluteGear, self).execute(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.height.Value == 0: fp.Shape = wi elif 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) # checksbackwardcompatibility: if not "da" in fp.PropertiesList: self.add_limiting_diameter_properties(fp) fp.da = "{}mm".format(fp.gear.da) fp.df = "{}mm".format(fp.gear.df)
def createOuterPartEqualHorizontal(cls, obj): """Create an outer part, where the left and the right outer dimensions M and M1 are equal.""" dims = cls.extractDimensions(obj) aux = dims.calculateAuxiliararyPoints() L = dims.H + dims.H1 r = dims.M2 / 2.0 h = dims.H2 vertical_outer_cylinder = Part.makeCylinder(r, h) r = dims.M / 2.0 h = L dr = FreeCAD.Vector(1, 0, 0) # Put cylinder along the x-axis. horizontal_outer_cylinder = Part.makeCylinder(r, h, aux["p1"], dr) outer_fusion = None enh = cls.horizontalWallEnhancement(obj) if enh is None: outer_fusion = horizontal_outer_cylinder.fuse( [vertical_outer_cylinder]) else: outer_fusion = horizontal_outer_cylinder.fuse( [vertical_outer_cylinder, enh]) return outer_fusion
def Activated(self): pos = App.Vector(-5, 0, 5) rot = App.Rotation(App.Vector(0, 1, 0), 90) newplace = App.Placement(pos, rot) cyx = Part.makeCylinder(2.0, 10.0) cyx.Placement = newplace App.ActiveDocument.addObject("Part::Feature", "cy_1") App.ActiveDocument.cy_1.Shape = cyx App.Console.PrintMessage('X axis cylinder initialized...\n') App.ActiveDocument.recompute() FreeCADGui.SendMsgToActiveView("ViewFit") ITSGui.existitem.append("cy_1") ITSGui.log.append('cy_x')
def setupUi(self): self.form.cboToolSelect.currentIndexChanged.connect(self.changeTool) self.form.tcoName.editingFinished.connect(self.getFields) # build the tool representation if self.obj.ToolNumber != 0: t = Part.makeCylinder(1, 1) self.toolrep = FreeCAD.ActiveDocument.addObject("Part::Feature", "tool") self.toolrep.Shape = t # setup the form fields self.setFields()
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
def Activated(self): cy2 = Part.makeCylinder(0.5, 0.5) pos = App.Vector(2.25, 0.25, 4) rot = App.Rotation(App.Vector(1, 0, 0), 90) newplace = App.Placement(pos, rot) cy2.Placement = newplace App.ActiveDocument.addObject("Part::Feature", "cy_2") App.ActiveDocument.cy_2.Shape = cy2 App.Console.PrintMessage('Y axis cylinder initialized...\n') App.ActiveDocument.recompute() FreeCADGui.SendMsgToActiveView("ViewFit") ITSGui.existitem.append("cy_2") ITSGui.log.append('cy_y')
def addscrewtab(self, screwPos): if self.tabbing.screwDiameter: margin = (self.tabbing.thickness - self.tabbing.screwDiameter) / 2 #self.addcut(screwPos - self.tabbing.screwDiameter / 2, self.tabbing.screwDiameter, margin, margin + self.tabbing.screwDiameter) cut = Part.makeCylinder( self.tabbing.screwDiameter / 2, self.tabbing.thickness * 3, self.c1.v + self.tabbing.thickness / 2 * self.cutDirection + screwPos * self.unitv - self.tabbing.thickness * 2 * self.cutNormal, self.cutNormal) if self.cuts is None: self.cuts = cut else: self.cuts = self.cuts.fuse(cut)
def lensShape(lens): '''Computes the 3D representation of the lens, a shape for a CAD file obj. lens: lens to represent. [GaussianBeam] Returns a shape for a CAD file object. ''' fact = settings.FCFactor #factor for units in CAD return Part.makeCylinder((lens.Dia / 2.) / fact, max(lens.Thick / fact, 0.01 / fact), Base.Vector(0, 0, 0), Base.Vector(tuple(-lens.HRNorm)))
def simple_buttons_model(input_parameters): """ Generates the geometry for the pillbox cavity in FreeCAD. Also writes out the geometry as STL files and writes a "sidecar" text file containing the input parameters used. Args: input_parameters (dict): Dictionary of input parameter names and values. """ try: wire1, face1 = make_elliptical_aperture(input_parameters['pipe_height'], input_parameters['pipe_width']) wire2, face2 = make_elliptical_aperture(input_parameters['pipe_height'] + input_parameters['pipe_thickness'], input_parameters['pipe_width'] + input_parameters['pipe_thickness']) beampipe_vac = make_beampipe(face1, input_parameters['pipe_length'] + 2e-3) beampipe = make_beampipe(face2, input_parameters['pipe_length']) block = Part.makeCylinder(input_parameters['block_radius'], input_parameters['block_s'], Base.Vector(-input_parameters['block_s'] / 2., 0, 0), Base.Vector(1, 0, 0) ) hole1 = single_button_hole(input_parameters, quadrants=(1, 1, 1)) hole2 = single_button_hole(input_parameters, quadrants=(-1, 1, -1)) hole3 = single_button_hole(input_parameters, quadrants=(-1, -1, 1)) hole4 = single_button_hole(input_parameters, quadrants=(1, -1, -1)) vac1 = beampipe_vac.fuse(hole1) vac2 = vac1.fuse(hole2) vac3 = vac2.fuse(hole3) vac4 = vac3.fuse(hole4) button_block = block.cut(vac4) beampipe1 = beampipe.cut(block) beampipe2 = beampipe1.cut(beampipe_vac) button1, pin1, ceramic1, shell1 = single_button(input_parameters, quadrants=(1, 1, 1)) button2, pin2, ceramic2, shell2 = single_button(input_parameters, quadrants=(-1, 1, -1)) button3, pin3, ceramic3, shell3 = single_button(input_parameters, quadrants=(-1, -1, 1)) button4, pin4, ceramic4, shell4 = single_button(input_parameters, quadrants=(1, -1, -1)) except Exception as e: raise ModelException(e) # An entry in the parts dictionary corresponds to an STL file. This is useful for parts of differing materials. parts = {'vac': vac4, 'block': button_block, 'beampipe': beampipe2, 'button1': button1, 'pin1': pin1, 'ceramic1': ceramic1, 'shell1': shell1, 'button2': button2, 'pin2': pin2, 'ceramic2': ceramic2, 'shell2': shell2, 'button3': button3, 'pin3': pin3, 'ceramic3': ceramic3, 'shell3': shell3, 'button4': button4, 'pin4': pin4, 'ceramic4': ceramic4, 'shell4': shell4 } # 'hole1': hole1, 'hole2': hole2, 'hole3': hole3, 'hole4': hole4 return parts, os.path.splitext(os.path.basename(MODEL_NAME))[0]
def createOuterPartReducedHorizontal(cls, obj): """Create a outer part which is cylinder+cone+cylinder+vertical cylinder. Also add an additional enhancement if the vertical part has too large diameter. """ dims = cls.extractDimensions(obj) aux = dims.calculateAuxiliararyPoints() # Create socket 1. r = dims.M / 2.0 h = dims.leftSocketOuterLength() dr = FreeCAD.Vector(1, 0, 0) # Put the cylinder along the x-ayis. cylinder1 = Part.makeCylinder(r, h, aux["p1"], dr) # Create a cone and put it at the right side of the cylinder 1. r1 = dims.M / 2.0 r2 = dims.M1 / 2.0 h = dims.G + dims.G1 dr = FreeCAD.Vector(1, 0, 0) cone = Part.makeCone(r1, r2, h, aux["p5"], dr) # Create a socket 2 and put it at the right side of the cone. r = dims.M1 / 2.0 h = dims.rightSocketOuterLength() dr = FreeCAD.Vector(1, 0, 0) # Put the cylinder along the x-ayis. cylinder2 = Part.makeCylinder(r, h, aux["p6"], dr) # Create vertical part. r = dims.M2 / 2.0 h = dims.H2 vertical_outer_cylinder = Part.makeCylinder(r, h) # Combine all four parts and, if necessary, add enhacement. enh = cls.horizontalWallEnhancement(obj) outer_fusion = None if enh is None: outer_fusion = cylinder1.fuse( [cone, cylinder2, vertical_outer_cylinder]) else: outer_fusion = cylinder1.fuse( [cone, cylinder2, vertical_outer_cylinder, enh]) return outer_fusion
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
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))
def createShape(self, feature): # TODO: use real shapes comp = Part.Compound([]) for jnt in self.kinematics.joints: m, Pjminus1 = self.kinematics.get_joint_transform(jnt) Pj = Base.Vector(m.A14, m.A24, m.A34) v = Pj - Pjminus1 if (v.Length > 0): body_shape = Part.makeCylinder(d_body, v.Length, Pjminus1, v) comp.add(body_shape) if (jnt.isrevolute()): joint_shape = Part.makeCylinder(d_rev, l_rev, Base.Vector(0, 0, -l_rev / 2)) elif (jnt.isprismatic()): joint_shape = Part.makeBox( d_prism, d_prism, l_prism, Base.Vector(-d_prism / 2, -d_prism / 2, -l_prism / 2)) if not (jnt.isfixed()): joint_shape.Matrix = m comp.add(joint_shape) # TODO: add the frame for each joint and add a property to switch # frame display on/off. feature.Shape = comp
def createSolidsAt(self, z, R): self.z = z self.toolRadius = R r1 = self.fullWidth() / 2 self.r1 = r1 self.r2 = r1 height = self.height * 1.01 radius = 0 if PathGeom.isRoughly(90, self.angle) and height > 0: # cylinder self.isSquare = True self.solid = Part.makeCylinder(r1, height) radius = min(min(self.radius, r1), self.height) PathLog.debug("Part.makeCone(%f, %f)" % (r1, height)) elif self.angle > 0.0 and height > 0.0: # cone rad = math.radians(self.angle) tangens = math.tan(rad) dr = height / tangens if dr < r1: # with top r2 = r1 - dr s = height / math.sin(rad) radius = min(r2, s) * math.tan((math.pi - rad) / 2) * 0.95 else: # triangular r2 = 0 height = r1 * tangens * 1.01 self.actualHeight = height self.r2 = r2 PathLog.debug("Part.makeCone(%f, %f, %f)" % (r1, r2, height)) self.solid = Part.makeCone(r1, r2, height) else: # degenerated case - no tag PathLog.debug("Part.makeSphere(%f / 10000)" % (r1)) self.solid = Part.makeSphere(r1 / 10000) if not PathGeom.isRoughly( 0, R): # testing is easier if the solid is not rotated angle = -PathGeom.getAngle(self.originAt(0)) * 180 / math.pi PathLog.debug("solid.rotate(%f)" % angle) self.solid.rotate(FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(0, 0, 1), angle) orig = self.originAt(z - 0.01 * self.actualHeight) PathLog.debug("solid.translate(%s)" % orig) self.solid.translate(orig) radius = min(self.radius, radius) self.realRadius = radius if not PathGeom.isRoughly(0, radius.Value): PathLog.debug("makeFillet(%.4f)" % radius) self.solid = self.solid.makeFillet(radius, [self.solid.Edges[0]])
def test04(self): '''Verify isVertical/isHorizontal for faces''' # planes xPlane = Part.makePlane(100, 100, Vector(), Vector(1, 0, 0)) yPlane = Part.makePlane(100, 100, Vector(), Vector(0, 1, 0)) zPlane = Part.makePlane(100, 100, Vector(), Vector(0, 0, 1)) xyPlane = Part.makePlane(100, 100, Vector(), Vector(1, 1, 0)) xzPlane = Part.makePlane(100, 100, Vector(), Vector(1, 0, 1)) yzPlane = Part.makePlane(100, 100, Vector(), Vector(0, 1, 1)) self.assertTrue(PathGeom.isVertical(xPlane)) self.assertTrue(PathGeom.isVertical(yPlane)) self.assertFalse(PathGeom.isVertical(zPlane)) self.assertTrue(PathGeom.isVertical(xyPlane)) self.assertFalse(PathGeom.isVertical(xzPlane)) self.assertFalse(PathGeom.isVertical(yzPlane)) self.assertFalse(PathGeom.isHorizontal(xPlane)) self.assertFalse(PathGeom.isHorizontal(yPlane)) self.assertTrue(PathGeom.isHorizontal(zPlane)) self.assertFalse(PathGeom.isHorizontal(xyPlane)) self.assertFalse(PathGeom.isHorizontal(xzPlane)) self.assertFalse(PathGeom.isHorizontal(yzPlane)) # cylinders xCylinder = [ f for f in Part.makeCylinder(1, 1, Vector(), Vector(1, 0, 0)).Faces if type(f.Surface) == Part.Cylinder ][0] yCylinder = [ f for f in Part.makeCylinder(1, 1, Vector(), Vector(0, 1, 0)).Faces if type(f.Surface) == Part.Cylinder ][0] zCylinder = [ f for f in Part.makeCylinder(1, 1, Vector(), Vector(0, 0, 1)).Faces if type(f.Surface) == Part.Cylinder ][0] xyCylinder = [ f for f in Part.makeCylinder(1, 1, Vector(), Vector(1, 1, 0)).Faces if type(f.Surface) == Part.Cylinder ][0] xzCylinder = [ f for f in Part.makeCylinder(1, 1, Vector(), Vector(1, 0, 1)).Faces if type(f.Surface) == Part.Cylinder ][0] yzCylinder = [ f for f in Part.makeCylinder(1, 1, Vector(), Vector(0, 1, 1)).Faces if type(f.Surface) == Part.Cylinder ][0] self.assertTrue(PathGeom.isHorizontal(xCylinder)) self.assertTrue(PathGeom.isHorizontal(yCylinder)) self.assertFalse(PathGeom.isHorizontal(zCylinder)) self.assertTrue(PathGeom.isHorizontal(xyCylinder)) self.assertFalse(PathGeom.isHorizontal(xzCylinder)) self.assertFalse(PathGeom.isHorizontal(yzCylinder))
def horizontalWallEnhancement(cls, obj): """Enchance wall, if the diameter of the vertical part is larger than the diamter of the horizontal partself. Add an additional cylinder to the outer part in the middle. """ dims = cls.extractDimensions(obj) if dims.M2 > dims.M or dims.M2 > dims.M1: r = dims.M2 / 2.0 h = dims.M2 p = FreeCAD.Vector(-dims.M2 / 2.0, 0, 0) # Direction where to rotate the cylinder dr = FreeCAD.Vector(1, 0, 0) return Part.makeCylinder(r, h, p, dr) else: return None
def execute(self, obj): import Part, FreeCAD d = Part.makeCylinder( obj.D.Value / 2.0, obj.Thk.Value, FreeCAD.Base.Vector(0, 0, -obj.Thk.Value / 2), ) p1 = Part.makeCylinder( obj.D.Value / 2.0, 0.01, FreeCAD.Base.Vector(0, 0, obj.PP1P.Value - obj.Thk.Value / 2), ) p2 = Part.makeCylinder( obj.D.Value / 2.0, 0.01, FreeCAD.Base.Vector(0, 0, obj.Thk.Value / 2 + obj.PP2P.Value), ) puppos = ( obj.PupP.Value - obj.Thk.Value / 2 if obj.PupRS else obj.PupP.Value + obj.Thk.Value / 2 ) pup = Part.makeCylinder( obj.PupD.Value / 2.0, 0.01, FreeCAD.Base.Vector(0, 0, puppos) ) if obj.SPP: oblist = [d, p1, p2] else: oblist = [d] if obj.PupEn: oblist = oblist + [pup] obj.Shape = Part.makeCompound(oblist)