From ShapeOko
Revision as of 06:30, 10 August 2021 by Willadams (Talk | contribs) (Interfaces)

Jump to: navigation, search

Forum user alpha mentioned this in OpenSCAD - The Programmers Solid 3D CAD Modeller, providing sample code for making a mounting plate.



Forum user cvoinescu noted in Re: OpenSCAD - The Programmers Solid 3D CAD Modeller

OpenSCAD exports an exact STL representation of its model. No approximations are made during export. However, the internal model is created as an approximation of what's described in the source code. When you say "cylinder", for instance, OpenSCAD actually creates a prism. You can control how many faces the prism has with the $fa, $fs and $fn variables and arguments. In many 3D prints, you can see the default $fa=12 having generated a 30-sided prism, which I find annoying.

Because OpenSCAD works only with polyhedra internally (or polygons, when using it for 2D stuff), it does not need to approximate anything when exporting STL (but see note below). This is also why its DXF export is rubbish, with everything made out of segments (well, technically, the export is perfect, it's the internal model that's not appropriate for creating DXFs).

Note: Don Bright, a member of the OpenSCAD mailing list pointed out that repeating decimals are of necessity truncated, “For example, a point at (1/3, 0, 0) gets converted into (0.3333333333, 0, 0) but of course, 0.33333333333 is an approximation of 1/3. ”


Turning the OpenSCAD into a GUI for other scripting languages

Interactive interface


Interface w/ Inkscape

Please note that there is a tool for Inkscape which will export files to a format suitable for import into OpenSCAD Inkscape gets OpenSCAD converter. (Also available here.)

Other vector apps

Thingiverse: Export OpenSCAD paths from Adobe Illustrator CS6 --- [1]

Exporting to Carbide Create

a technique for loading the JSON from an OpenSCAD customizer and using it to generate a PDF or SVG:

Importing .stl Files

rotate([0, 0, 0]) import_stl("<filename>.stl");

Thingiverse: STL to OpenSCAD converter

CAM options for OpenSCAD

Export to DXF or SVG for CAM

Rather than attempt to use 3D (stl) representation, one may instead flatten a drawing in sections using code like:

projection(cut=true) translate([0, 0, -3]) {...object code / reference here...};

which is suggested in Hints for 2D modeling with OpenSCAD (DXF). This will allow one to export the design as .dxf(s) which may then be used in a traditional CAD/CAM workflow, or by importing into a drawing program and handling each layer by hand.

A similar technique is suggested in OpenSCAD to DXF and a script is provided here.


Exporting a design as a 3D STL file will allow machining it or 3D printing it using a traditional 3D CAM tool or 3D printer slicing tool within the limits of the triangular tessellation which is exported.

Import to FreeCAD

An OpenSCAD file may be imported into FreeCAD and CAM performed in the Path Workbench.

Using FreeCAD:

CNC direct interfaces [2]

Discussion: [3]

Parallel programming



Thingiverse Customizer:

Other Support Tools

Begin with:

Labelling and Dimensioning of Parts

Sample Files

There are a number of repositories with especial support for OpenSCAD including Thingiverse and


Diamond Circle Square 3D Example

Diamond-circle-square OpenSCAD.png

Creating a test file for this is quite straight-forward in OpenSCAD (code courtesy of Triffid Hunter[21], see the thread (OpenSCAD) machinist's diamond-circle-square test for a tutorial on the ShapeOko wiki for further discussion and notes on how the file shows good working practices):

$fa = 0.01; // allow $fs to work correctly
$fs=0.5; // segment length of circle circumference

r_square = 50;
r_circle = 45;
r_diamond = 40;
l_height = 3;

translate([0, 0, l_height * 0.5]) {
    cube([r_square,r_square,l_height], center=true);
    #linear_extrude(height=l_height * 1.5)
    cylinder(r=r_diamond/2, h=l_height * 2.5, $fn=4);

Peter Falke provided a nice example as well [22].

The file may then be (Design | ) "Compile and Render"ed to prepare it for exporting as a .stl file which may then be processed in a CAM program for machining as described in Basic workflow 3D


References --- discussions of how variables are treated in OpenSCAD.