Scripted Parts: Ball Bearing - Part 2/en

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
 * Draw the basic shape of the outer ring consisting of four straight lines and four arcs
 * Connect the lines and arcs and upgrade them to one single wire
 * Upgrade the wire to a face
 * Revolve the face to get a shape
 * Draw a circle
 * Upgrade circle to wire
 * Upgrade wire to face
 * Revolve face and apply boolean cut to obtain groove in outer ring
 * Draw the basic shape of the inner ring consisting of four straight lines and four arcs
 * Connect the lines and arcs and upgrade them to one single wire
 * Upgrade the wire to a face
 * Revolve the face to get a shape
 * Draw a circle
 * Upgrade circle to wire
 * Upgrade wire to face
 * Revolve face and apply boolean cut to obtain groove in inner ring
 * Insert balls with same workflow as in part 1 (because of effectiveness)
 * Set view to axometric
 * Zoom to fit all

Making the groove
Drawing an arc needs either three points or a start angle and an end angle.

In the sketcher we would use constraints to define the start point and the end point of the arc.

Since we can't do this in scripting, we draw a rounded rectangle and revolve it to get a basic "ring shape".

Then we draw a circle and revolve it to get the geometry of the groove.

Then we apply a boolean cut to the two revolved shapes and we have the complete shape of the inner/outer ring.

Inserting the balls
The correct sketcher-based workflow of inserting the balls would be:


 * Draw an arc (semi-circle) with center being identical with the origin and draw a line closing the "open" side of the arc
 * Convert the two elements to a wire, upgrade to a face, revolve around z-axis to get a ball shape
 * Use "translate" command to move the ball into correct position
 * Repeat the above steps nine times involving math function to create and position the other balls
 * This repeat-operation could be programmed with a loop

Now this is not effective, inserting primitives and positioning them is easier and faster in this case.

So we use the same method as in "Scripted Parts: Ball Bearing - Part 1".

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