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

From FreeCAD Documentation
No edit summary
No edit summary
Line 10: Line 10:
}}
}}



<!--T:2-->
===Introduction===
===Introduction===<!--T:2-->
This tutorial is meant as a beginner's introduction to creating parts with python scripts within FreeCAD.<br />
This tutorial is meant as a beginner's introduction to creating parts with python scripts within FreeCAD.<br />
This tutorial will cover how to build a ball bearing with a workflow that consists of creating sketches and revolving them.<br />
This tutorial will cover how to build a ball bearing with a workflow that consists of creating sketches and revolving them.<br />
Line 19: Line 19:
[[Image:Tutorial_BallBearing01.jpg|400px]]
[[Image:Tutorial_BallBearing01.jpg|400px]]



<!--T:3-->
===Workflow===
===Workflow===<!--T:3-->
The workflow is more or less identical how you would create the part in part design workbench.<br />
The workflow is more or less identical how you would create the part in part design workbench.<br />
Just some small differences.<br />
Just some small differences.<br />
Line 29: Line 29:
*Zoom to fit all
*Zoom to fit all



<!--T:4-->
===Making the groove===
===Making the groove===<!--T:4-->
Bla and blub ...
Bla and blub ...


<!--T:5-->
===Inserting the balls===<!--T:5-->

===Notes===

===Notes===<!--T:6-->
Bla and blub ...
Bla and blub ...



<!--T:6-->
===Links===
===Links===<!--T:7-->
[[Scripted objects]]: The wiki page explaing the basics of scripting<br />
[[Scripted objects]]: The wiki page explaing the basics of scripting<br />
[[Topological data scripting]]: A tutorial for covering basics of scripting<br />
[[Topological data scripting]]: A tutorial for covering basics of scripting<br />
Line 44: Line 46:
[http://linuxforanengineer.blogspot.de/2013/12/bearings-from-scripted-sketches.html Bearings from scripted sketches]: Base for this tutorial, thanks to JMG ...<br />
[http://linuxforanengineer.blogspot.de/2013/12/bearings-from-scripted-sketches.html Bearings from scripted sketches]: Base for this tutorial, thanks to JMG ...<br />



<!--T:7-->
===Code===
===Code===<!--T:8-->
{{Code|code=
{{Code|code=
## Ball-bearing script
## Ball-bearing script
Line 87: Line 89:
Gui.ActiveDocument=Gui.getDocument("Unnamed")
Gui.ActiveDocument=Gui.getDocument("Unnamed")


#Lines for basic shape of outer ring
L1o=Part.makeLine((R3,0,RR),(R3,0,TH-RR))
L2o=Part.makeLine((R3+RR,0,TH),(R4-RR,0,TH))
L3o=Part.makeLine((R4,0,TH-R),(R4,0,TH))
L4o=Part.makeLine((R4-RR,0,0),(R3+RR,0,0))
#Corner rounding for basic shape of outer ring
A1o=Part.makeCircle(r1a,Base.Vector(btha-r1a,rtha-r1a,0),Base.Vector(0,0,1),0,90)
A2o=Part.makeCircle(r2a,Base.Vector(btha-r2a,r2a,0),Base.Vector(0,0,1),270,360)
A3o=Part.makeCircle(r2a,Base.Vector(r2a,r2a,0),Base.Vector(0,0,1),180,270)
A4o=Part.makeCircle(r1a,Base.Vector(r1a,rtha-r1a,0),Base.Vector(0,0,1),90,180)
#Connect Lines and arcs to make wire and upgrade to face
Ur=Part.Wire([L1a,A1a,L2a,A2a,L3a,A3a,L4a,A4a])
Ur=Part.Face(Ur)
#VUR=(0,rout-rtha,0)
#Ur.translate(VUR)
Ur=Ur.revolve(Base.Vector(0,0,0),Base.Vector(360,0,0))
#Todo
#Todo



Revision as of 11:20, 16 August 2016

Tutorial
Topic
Part Scripting - Ball Bearing #2
Level
Beginner
Time to complete
30 min
Authors
r-frank
FreeCAD version
0.16.6706
Example files
See also
None


Introduction

This tutorial is meant as a beginner's introduction to creating parts with python scripts within FreeCAD.
This tutorial will cover how to build a ball bearing with a workflow that consists of creating sketches and revolving them.
The code will produce a new FreeCAD document with 12 shapes (Inner Ring, Outer Ring and 10 balls/spheres).
It will look like this:


Workflow

The workflow is more or less identical how you would create the part in part design workbench.
Just some small differences.

  • Create a new empty document and make it the active document


  • Set view to axometric
  • Zoom to fit all


Making the groove

Bla and blub ...

Inserting the balls

Notes

Bla and blub ...


Links

Scripted objects: The wiki page explaing the basics of scripting
Topological data scripting: A tutorial for covering basics of scripting
Scripted Parts: Ball Bearing - Part 1: Doing it with part primitives
Bearings from scripted sketches: Base for this tutorial, thanks to JMG ...


Code

## Ball-bearing script
## 11.08.2016 by r-frank (BPLRFE/LearnFreeCAD on Youtube)
## based on ball bearing script by JMG
## (http://linuxforanengineer.blogspot.de/2013/12/bearings-from-scripted-sketches.html)

#needed for doing boolean operations
import Part
#needed for calculating the positions of the balls
import math
#needed for translation and rotation of objects
from FreeCAD import Base

#VALUES#
#(radius of shaft/inner radius of inner ring)
R1=15.0
#(outer radius of inner ring)
R2=25.0
#(inner radius of outer ring)
R3=30.0
#(outer radius of outer ring)
R4=40.0
#(thickness of bearing)
TH=15.0
#(number of balls)
NBall=10
#(radius of ball)
RBall=5.0
#(rounding radius for fillets)
RR=1
#first coordinate of center of ball
CBall=((R3-R2)/2)+R2
#second coordinate of center of ball
PBall=TH/2

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

#Lines for basic shape of outer ring
L1o=Part.makeLine((R3,0,RR),(R3,0,TH-RR))
L2o=Part.makeLine((R3+RR,0,TH),(R4-RR,0,TH))
L3o=Part.makeLine((R4,0,TH-R),(R4,0,TH))
L4o=Part.makeLine((R4-RR,0,0),(R3+RR,0,0))
#Corner rounding for basic shape of outer ring
A1o=Part.makeCircle(r1a,Base.Vector(btha-r1a,rtha-r1a,0),Base.Vector(0,0,1),0,90)
A2o=Part.makeCircle(r2a,Base.Vector(btha-r2a,r2a,0),Base.Vector(0,0,1),270,360)
A3o=Part.makeCircle(r2a,Base.Vector(r2a,r2a,0),Base.Vector(0,0,1),180,270)
A4o=Part.makeCircle(r1a,Base.Vector(r1a,rtha-r1a,0),Base.Vector(0,0,1),90,180)
#Connect Lines and arcs to make wire and upgrade to face
Ur=Part.Wire([L1a,A1a,L2a,A2a,L3a,A3a,L4a,A4a])
Ur=Part.Face(Ur)
#VUR=(0,rout-rtha,0)
#Ur.translate(VUR)
Ur=Ur.revolve(Base.Vector(0,0,0),Base.Vector(360,0,0))
#Todo


#Make it pretty#
App.activeDocument().recompute()
Gui.activeDocument().activeView().viewAxometric()
Gui.SendMsgToActiveView("ViewFit")