Scripted Parts: Ball Bearing - Part 1: Difference between revisions

From FreeCAD Documentation
No edit summary
No edit summary
Line 49: Line 49:


#Create new document
#Create new document
App.newDocument("Unbenannt")
Create new document
App.setActiveDocument("Unbenannt")
App.ActiveDocument=App.getDocument("Unbenannt")
Gui.ActiveDocument=Gui.getDocument("Unbenannt")


#Inner Ring#
#Inner Ring#
Line 81: Line 84:


#Make it pretty#
#Make it pretty#
Active.document.recompute()
App.activeDocument().recompute()
Gui.activeDocument().activeView().viewAxometric()
View.Axometric
Gui.SendMsgToActiveView("ViewFit")
FitAll
}}
}}



Revision as of 19:57, 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
App.newDocument("Unbenannt")
App.setActiveDocument("Unbenannt")
App.ActiveDocument=App.getDocument("Unbenannt")
Gui.ActiveDocument=Gui.getDocument("Unbenannt")

#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#
App.activeDocument().recompute()
Gui.activeDocument().activeView().viewAxometric()
Gui.SendMsgToActiveView("ViewFit")