My name is Javier and I am Mechanical Engineering student from Spain. I have been interested in FreeCAD few month and just this week I have started to write some python code. At the moment I am trying to create a tool that I have called "Bearing Creator". The idea is to have a graphical way to generate bearings and put them in an assembly (too ambitious I think). I have searched in the forum for similar project and I have found a post discussing something about bearings, but is stagnant. At the moment I am able to create fixed ball bearings from a script and I have created a graphical dialog too (only test functional). With time I think I can complete it.
The plain code that creates the bearings is:
Code: Select all
import Part import math #Variable R1=15.0 R2=25.0 R3=30.0 #Variables. The main body of the bearing is created from 4 cylinders R4=40.0 TH=20.0 #Ball bearing thickness NBall=10 #Ball number RBall=5.0 #Ball radius RR=1 #Bearing edges rounding value B1=Part.makeCylinder(R1,TH) B2=Part.makeCylinder(R2,TH) IR=B2.cut(B1) # Creates inner ring. FI=IR.Edges IR=IR.makeFillet(RR,FI) B3=Part.makeCylinder(R3,TH) B4=Part.makeCylinder(R4,TH) OR=B4.cut(B3) #Creates outter ring FO=OR.Edges OR=OR.makeFillet(RR,FO) T1=Part.makeTorus(R2+(RBall/2),RBall) VT=(0,0,TH/2) T1.translate(VT) #Creates ball race IR=IR.cut(T1) OR=OR.cut(T1) Part.show(IR) Part.show(OR) CBall=((R3-R2)/2)+R2 PBall=TH/2 for i in range(NBall): #Creates a number of NBalls Ball=Part.makeSphere(RBall) Alpha=(i*2*math.pi)/NBall BV=(CBall*math.cos(Alpha),CBall*math.sin(Alpha),TH/2) Ball.translate(BV) Part.show(Ball)
This is the result.
The graphical dialog menu has very simple parameters and the workflow is:
1-Select Bearing type(Fixed,Axial,Tapered,all)
2-Select Measure(Inner radius, Outter radius, width, search(just search in database))
3-Select/Type Measure Value
4-Select Bearing that suits from the found bearing list.
The idea is, once you are in the assembly, select a cylinder (or not), select the tool and the program should be able to put your desired bearing at the position selected.
Issues I have at the moment:
-my menu dialog only shows up the first time I import it. I type "import Bearing" and it shows, but if I close it, will never show again.
-Is possible to fusion all the parts created by the script? I have tried with the fusion tool but FreeCAD just stops working until I kill it. I think that maybe because the bearing will be a part inside the assembly this is unnecesary.
-What is more efficient(memory, speed,...): Create the bearing from booleans or use sketches?
I am very new at FreeCAD scripting, do not hesitate to point my errors