An introduction to OpenSCAD

OpenSCAD

OpenSCAD is a rather simple to use, open-source, CAD-software which is more than enough to create the custom PCB shapes we may need. It is available for Windows, OSX and Linux: www.openscad.org. This introduction to OpenSCAD will focus on creating 2D-shapes for use as custom PCB shapes.

OpenSCAD

OpenSCAD syntax

Since we are creating shapes for the outline of the PCB, we only care about the 2-dimensional objects available in OpenSCAD which are projected onto the xy-plane when rendered. It is, however, possible to model 3-dimensional objects using OpenSCAD.

The syntax itself is very simple and we’ll go through some basic functions that may be of use when creating the shape of your PCB. Note that OpenSCAD is unitless and it is ultimately the “receiving” application (or manufacturer) that may determine which unit is used for measurements.

The $fn-variable

The $fn-variable is a special variable, which can be used together with shape-functions to create high-resolution shapes. This variable determines the amount of points which create the shape. See the image below for some references.

Some $fn-values

Now this could be valuable not only for creating high-resolution circles, but also if we want to create a hexagon, octagon and so on.

2D-Shapes

square

This function allows us to create a 2-dimensional square or rectangle. It has two arguments:

Argument Type Description
size decimal or [decimal, decimal] Sides of square/rectangle. The name of this argument may be omitted.
center boolean If square is to be centered at (0,0) or set lower “left” corner at (0,0). Default is FALSE.
circle

This function allows us to create a 2-dimensional circle. To create an oval shape, we can use the circle in combination with the resize function.

Argument Type Description
r decimal Radius of circle. The name of this argument may be omitted.
d decimal Diameter of the circle. Used instead of r.
polygon

This function allows us to create a 2-dimensional polygon of complex shape, which may come in handy if the PCB is to be a complex shape.

Argument Type Description
points [[x1,y1],…,[xn,yn]] The list of points in the polygon, a vector of 2-value vectors.
path [integer] or [[integer], [integer]] Either a single vector enumerating the points in traverse order or a vector of vectors containing enumerated points to define multiple paths of the polygon. This is optional and if omitted, the points will be used in order as path.
convexity integer Number of expected path crossings (see the OpenSCAD user manual).
Triangle with cut-out center

Combining- and transforming shapes

translate

This function allows us to move an object wherever we want in x-y-z space.

Argument Type Description
v [x,y,z] Vector of decimals for x,y and z-position to translate (move) to.
rotate

This function allows us to rotate an object. It can be used in fairly complex ways, but we’ll only cover its simplest use, rotation in 2d-space.

Argument Type Description
a integer or [x,y,z] Degrees to rotate. Either single value to rotate around z-axis OR as a vector with degrees per axis.
v [x,y,z] An arbitrary vector around which the object may be rotated. Ignored if a is set as vector.
The two examples, side by side (at an angle to show rotations).
resize

This function allows us to resize an object. It can be used to, for example, create a oval shape from a circle.

Argument Type Description
newsize [x,y,z] New size in x, y and z-axis.
The resized circle.
mirror

Mirrors the child node on a plane through origo. Mirror takes one unnamed argument, which is the normal to the reflection-plane.

Argument Type Description
N/A [x,y,z] Normal of the plane in which the child node is to be mirrored.
Mirrored mickey-mouse in y/z-plane.
minkowski

The minkowski sum allows us to, in an easy way, to add (for example) rounded corners to a cube. The function takes no arguments. Note that if minkowski is used as in the example, the overall width of the object is the width of the square plus the length of the radius of the circle times two (square_width + 2 * circle_radius);

The result of the minkowski transformation.
hull

Displays the convex hull of the objects (child nodes)

The hull-result.
union

Combines the child nodes into a single object.

Mickey Mouse union.
difference

Cuts away intersecting parts of the child nodes from the first child node.

Mickey Mouse cutout.
intersection

Intersection keeps the overlapping parts of the child nodes.

The intersection of three circles.

Now to render the PCB-shape in OpenSCAD. This can be done by clicking Design > Render in the application menu, Render in the icon-toolbar below the render-window or simply by pressing F6.

Further reading

For further reading on OpenSCAD, see the OpenSCAD User Manual.

From OpenSCAD to other programs

The first step is to make sure the shape is rendered correctly, otherwise the export to a more widely adopted format may not be correct. OpenSCAD allows for exporting the shape to multiple different formats which then can be imported by other programs. These formats are STL, OFF, AMF, DXF, SVG, CSG. Which one is right for you depends on the situation, but if you are in need of a format that is easy to parse — the DXF-format (Design eXchange Format) is a good choice.