## Introduction and Bearing Creator Tool

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
javiermg
Posts: 7
Joined: Mon Aug 12, 2013 11:04 am

### Introduction and Bearing Creator Tool

Hi all!

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
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)
3-Select/Type Measure Value
4-Select Bearing that suits from the found bearing list.
5-Done!

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

Thanks!
wmayer
Posts: 15128
Joined: Thu Feb 19, 2009 10:32 am

### Re: Introduction and Bearing Creator Tool

-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.
Either call

Code: Select all

``reload(Bearing)``
or better make a function where you put all the dialog stuff, e.g. showDialog(). Then you only have to call this function to show again the dialog.
-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.
All the objects only touch at single points so that a boolean operation would never create a valid result. Instead you should create a compound which acts like a simple container of shapes.

Code: Select all

``````shapes=[]
...
shapes.append(IR)
shapes.append(OR)
...
shapes.append(Ball)
...
comp=Part.Compound(shapes)
Part.show(comp)
``````
javiermg
Posts: 7
Joined: Mon Aug 12, 2013 11:04 am

### Re: Introduction and Bearing Creator Tool

mario52
Posts: 2755
Joined: Wed May 16, 2012 2:13 pm

### Re: Introduction and Bearing Creator Tool

hi
Unable to create a sphere or torus reflected FreeCAD constantly !
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
mario52
Posts: 2755
Joined: Wed May 16, 2012 2:13 pm

### Re: Introduction and Bearing Creator Tool

hi
an idea of why I do not create sphere and torus ?
thanks
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
triplus
Posts: 8878
Joined: Mon Dec 12, 2011 4:45 pm

### Re: Introduction and Bearing Creator Tool

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.
Interesting idea yes and it would be nice to have something like this.
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

### Re: Introduction and Bearing Creator Tool

I am working on something very similar in spirit (a cross-CAD standard parts repository), I have created a thread on it here:

viewtopic.php?f=8&t=4549

There might be interesting overlaps with your work here, I have to look at it in detail.

Greetings
bejant
Posts: 6023
Joined: Thu Jul 11, 2013 3:06 pm

### Re: Introduction and Bearing Creator Tool

mario52 wrote:Unable to create a sphere or torus reflected FreeCAD constantly !
Hi Mario, I noticed your questions haven't been answered, can you provide more details? Without them I'm not sure I can be of much help; but I can let you know I don't have a problem creating either a torus or sphere:

https://www.dropbox.com/s/aqv2xctz2obsa ... Sphere.avi

OS: Windows XP
Platform: 32-bit
Version: 0.14.2370 (Git)
Branch: master
Hash: a836759ebd91404954a778ff8885e152611576e1
Python version: 2.6.2
Qt version: 4.5.2
Coin version: 3.1.0
SoQt version: 1.4.1
OCC version: 6.5.1
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

### Re: Introduction and Bearing Creator Tool

Hi javier and all,

thank you very much for this very nice macro.

I just tried to adapt it for use with BOLTS (see viewtopic.php?f=8&t=4549), to see what I need to do to make it work. It went relatively flawless:

* I put the code in a function, added some parameter unpacking code and grouped all shapes into a compound as suggested by wmayer.
* Then I got some dimensions from this site http://www.kgm-kugeln.de/downloads_4444.html and put them in a blt file.
* I needed to do some changes to my gui code, but I got it to work.

You can try it with the attached archive, the instructions are the same as on the BOLTS page: http://jreinhardt.github.io/BOLTS/index.html
You can see the modified code and blt file when you have extracted the archive in the files freecad/bearings.py and blt/bearings.blt

I did not include it into BOLTS yet, because I wanted to ask you first, if you are ok with that. I do not want to hijack your project or prevent you from learning FreeCAD, it is just that bearings would make a great addition to BOLTS. If you are ok with that, under what license do you want to put the macro code?
Attachments
mario52
Posts: 2755
Joined: Wed May 16, 2012 2:13 pm

### Re: Introduction and Bearing Creator Tool

hi
thanks
bejant wrote:
mario52 wrote:Unable to create a sphere or torus reflected FreeCAD constantly !
Hi Mario, I noticed your questions haven't been answered, can you provide more details? Without them I'm not sure I can be of much help; but I can let you know I don't have a problem creating either a torus or sphere:
Yes Unable to create an a sphere and a torus FreeCAD consumes more and more memory until slow but built nothing and ignites all the time
(Oui impossible de créer une une sphère et un tore FreeCAD consomme de plus en plus de mémoire jusqu'a ralentir tout le système mais ne construit rien et réfléchit tout le temps)
Vista sp2 FreeCAD 0.13 et 0.14
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.