Tuesday 13 August 2013

FreeCad Bearing Script 2

Embedded balls on rings are not really good looking, but until today I didn't figure how to create them without revolving a sketch. Solution has been as simple as creating a torus between rings and substract it to them. (full script at the end of the post)


Code:

T=Part.makeTorus(R1,R2)

This instruction will create a torus with big radius R1 and small radius R2 at (0,0,0).

To move it to its position in the bearing:

V=(0,0,TH/2)

TH/2 because track is in the middle of the bearing z axis (remember TH variable defined in previous post "FreeCad Bearing Script")

Show:

Part.show(T)

With this you have a groove with a radius R2 a radial distance R1 just in middle of the bearing, a little improvement to our bearing.


Added: Round edges:

After a bit of research I found how to select edges and how to fillet them, just two commands.

First, we create a new variable that I`ve called RR and contains the value of the rounding radius.

RR=1 

To explain the commands I am going to use a box object:

B=Part.makeBox(30,30,30)

Do not create a very tiny box or making fillet will crash freecad.

Getting the box edges (all) and store them in Bedges new variable:

Bedges=B.Edges

Fillet:

BFillet=B.makeFillet(RR,Bedges)

This instructions creates BFillet object that is our B box with all its edges rounded with an RR radius.

Part.show(BFillet)

This should be the result:


How can we apply this to our bearing? (understand "FreeCad Bearing Script 1" needed)
This way:

Create inner ring:

B1=Part.makeCylinder(R1,TH)
B2=Part.makeCylinder(R2,TH)
IR=B2.cut(B1)

Now just round the ring:

FI=IR.Edges
IR=IR.makeFillet(RR,FI)

And its done!

Part.show(IR)



Full code:

import Part
import math

#VARIABLE VALUES#

R1=15.0
R2=25.0
R3=30.0
R4=40.0
TH=15.0
NBall=10
RBall=5.0
RR=1

#Program#

B1=Part.makeCylinder(R1,TH)
B2=Part.makeCylinder(R2,TH)
IR=B2.cut(B1)
FI=IR.Edges
IR=IR.makeFillet(RR,FI)


B3=Part.makeCylinder(R3,TH)
B4=Part.makeCylinder(R4,TH)
OR=B4.cut(B3)
FO=OR.Edges
OR=OR.makeFillet(RR,FO)

T1=Part.makeTorus(R2+(RBall/2),RBall)
VT=(0,0,TH/2)
T1.translate(VT)

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):
  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)

  

  The output of that command is the picture at the beginning of this post.

Added: Video of the script working



Next things to do are grouping all entities in the same object and create a standard bearing generator script.

I have realized that there is no way (at least graphically) to create section views or cuts to 3d parts. A very useful tool to show internals. Also I have not found at the moment any way to measure distance or angles of points, edges, axis... Maybe in the next release.

Bye!


No comments:

Post a Comment