Scripted Parts: Ball Bearing - Part 1: Difference between revisions
No edit summary |
No edit summary |
||
Line 11: | Line 11: | ||
<!--T:2--> |
<!--T:2--> |
||
===Introduction=== |
|||
Todo |
|||
<!--T:3--> |
<!--T:3--> |
||
===Workflow=== |
|||
Todo |
|||
<!--T:4--> |
<!--T:4--> |
||
===Filleting edges=== |
|||
Todo |
|||
<!--T:5--> |
<!--T:5--> |
||
===Notes=== |
|||
Todo |
|||
<!--T:6--> |
<!--T:6--> |
||
===Links=== |
|||
Todo |
|||
<!--T:7--> |
<!--T:7--> |
||
===Code=== |
|||
Todo |
|||
{{Code|code= |
|||
## Ball-bearing script |
|||
## 11.08.2016 by r-frank (BPLRFE on Youtube) |
|||
## based on ball bearing script by JMG |
|||
## (http://linuxforanengineer.blogspot.de/2013/08/free-cad-bearing-script.html) |
|||
import Part |
|||
import math |
|||
#VALUES# |
|||
R1=15.0 #(radius of shaft/inner radius of inner ring) |
|||
R2=25.0 #(outer radius of inner ring) |
|||
R3=30.0 #(inner radius of outer ring) |
|||
R4=40.0 #(outer radius of inner ring) |
|||
TH=15.0 #(thickness of bearing) |
|||
NBall=10 #(number of balls) |
|||
RBall=5.0 #(radius of ball) |
|||
RR=1 #(rounding radius) |
|||
CBall=((R3-R2)/2)+R2 #first coordinate of center of ball |
|||
PBall=TH/2 #second coordinate of center of ball |
|||
#Create new document |
|||
Create new document |
|||
#Inner Ring# |
|||
B1=Part.makeCylinder(R1,TH) |
|||
B2=Part.makeCylinder(R2,TH) |
|||
IR=B2.cut(B1) |
|||
Bedges=IR.Edges #get edges |
|||
IRF=IR.makeFillet(RR,Bedges) #apply fillets |
|||
T1=Part.makeTorus(CBall,RBall) #needed for ball groove |
|||
Inner_Ring=T1.cut(IRF) |
|||
#Outer Ring# |
|||
B3=Part.makeCylinder(R3,TH) |
|||
B4=Part.makeCylinder(R4,TH) |
|||
OR=B4.cut(B3) |
|||
Bedges=OR.Edges #get edges |
|||
ORF=OR.makeFillet(RR,Bedges) #apply fillets |
|||
T2=Part.makeTorus(CBall,RBall) #needed for ball groove |
|||
Outer_Ring=T2.cut(ORF) |
|||
Part.show(Inner_Ring) |
|||
Part.show(Outer_Ring) |
|||
#Balls# |
|||
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) |
|||
#Make it pretty# |
|||
Active.document.recompute() |
|||
View.Axometric |
|||
FitAll |
|||
}} |
|||
<!--T:8--> |
|||
Todo |
|||
</translate> |
</translate> |
Revision as of 12:05, 10 August 2016
Tutorial |
Topic |
---|
Part Scripting - Ball Bearing #1 |
Level |
Beginner |
Time to complete |
30 min |
Authors |
r-frank |
FreeCAD version |
0.16.6706 |
Example files |
See also |
None |
Introduction
Workflow
Filleting edges
Notes
Links
Code
## Ball-bearing script
## 11.08.2016 by r-frank (BPLRFE on Youtube)
## based on ball bearing script by JMG
## (http://linuxforanengineer.blogspot.de/2013/08/free-cad-bearing-script.html)
import Part
import math
#VALUES#
R1=15.0 #(radius of shaft/inner radius of inner ring)
R2=25.0 #(outer radius of inner ring)
R3=30.0 #(inner radius of outer ring)
R4=40.0 #(outer radius of inner ring)
TH=15.0 #(thickness of bearing)
NBall=10 #(number of balls)
RBall=5.0 #(radius of ball)
RR=1 #(rounding radius)
CBall=((R3-R2)/2)+R2 #first coordinate of center of ball
PBall=TH/2 #second coordinate of center of ball
#Create new document
Create new document
#Inner Ring#
B1=Part.makeCylinder(R1,TH)
B2=Part.makeCylinder(R2,TH)
IR=B2.cut(B1)
Bedges=IR.Edges #get edges
IRF=IR.makeFillet(RR,Bedges) #apply fillets
T1=Part.makeTorus(CBall,RBall) #needed for ball groove
Inner_Ring=T1.cut(IRF)
#Outer Ring#
B3=Part.makeCylinder(R3,TH)
B4=Part.makeCylinder(R4,TH)
OR=B4.cut(B3)
Bedges=OR.Edges #get edges
ORF=OR.makeFillet(RR,Bedges) #apply fillets
T2=Part.makeTorus(CBall,RBall) #needed for ball groove
Outer_Ring=T2.cut(ORF)
Part.show(Inner_Ring)
Part.show(Outer_Ring)
#Balls#
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)
#Make it pretty#
Active.document.recompute()
View.Axometric
FitAll