3D Printing


On this page:

Converting a design to 2D plans

OpenSCAD1 has the option to produce 2D files in DXF2 format as either a solid projection to the XY plane, or as the intersection (cut) with the XY plane. By moving the object up and down in the Z axis, different intersections can be generated. If the model is rotated on the X or Y axis, movement on the Z axis will produce elevation views.

In practice

The settings have to be determined in the GUI interface based on the known dimensions of the model, and may just consist of a set of Z axis displacements. For more complex plans involving elevations, rotations must be included. The OpenSCAD file needs to have variables defined to a) enable projection, b) provide the Z axis displacement and optionally c) the rotation matrix to apply. For simple plan views the rotation matrix will be [0,0,0]. It may be possible to predict the layers required for the plans from the original model design. However from an STL file this may have to be done by inspection in the GUI, or by generating a coarse step set and refining that to find the optimum Z displacements and rotations.

To get the plans, OpenSCAD will need to be run from the command line, specifying the output filename (including any number scheme), the values needed for a, b, and possibly c. This can be wrapped in a shell script which may read the parameters from a control file. The final result should be a set of DXF files reflecting the 2D plans for the model. Obviously, modifications to the 3D model may require the regeneration of the 2D set.

Since OpenSCAD is run for each plan, the total execution time will be proportional to the number of plans generated - the program has to render the full object each time. There will be some variation depending on how much of the object intersects with the chosen XY plane, and how complex it is to rotate/translate the object to cross that plane.

An alternative approach is to render the model and export an STL3 file. Or use a pre-existing STL file. OpenSCAD will load an STL file, so it is possible to write a little OpenSCAD program that does the projection() translate() rotate() load(); sequence, and then run it. If the small driver OpenSCAD program is re-written with the correct embedded values, it can be used multiple times. So it is possible to use the command file to (re)write the script to process the STL file using translate and rotate parameters required.

An example of a small OpenSCAD wrapper around an STL file:

// 2D Plan extraction from a 3D object (STL source)
// Author: Graham Patterson, 2023
// This method uses a pre-created STL file of the object, an
// optional rotation, and an optional translate adjustment. 
// projection(cut = true) renders the 2D slice of the object in 
// the XY plane. By adjusting the Z offset, slices can be taken
// through the object. Typically this is done at depths that best
// reveal the object structure. 
// Rotation may have to take in to account where the three axis 
// center is in relation to the model. 
// Variables that may be set from the command line
zoffset = 0;
rotatearray = [0,0,0];

echo("zoffset = ", zoffset);
projection(cut = true) 

    rotate(rotatearray) // Leave as [0,0,0] for no rotation
    // This is an STL file created from an OpenSCAD design, and chosen at random for testing. Substitute your own file.
// End of file

This could be run using the following (on Windows in this case):

"c:\program files\openscad\openscad.exe" -o test.dxf -D zoffset=-10 2Drender.scad

where the -D definition over-rides the value set in the program and drops the object 10mm on the Z axis. Wrapping this into a command file to add a variable for the offset and append a number to the file name means a set of plans can be generated. The exact ‘recipe’ will depend on the object, the dimensions, and any elevations required.

Or for a Windows driver script:

@echo off
REM Driver program for creating plan slices in DXF format of an object using OpenSCAD
REM The slices run on a free core will run fast. Subsequent slices that 
REM get queued on busy cores will take longer. This will send the CPU to
REM 100%, so be aware of other jobs on the system

REM "c:\program files\openscad\openscad.exe" -o test.dxf -D zoffset=-10 2Drender.scad
SET SCADAPP="c:\program files\openscad\openscad.exe"

FOR /L %%I IN (0, -1, -15) DO CALL :PROCstart %%I

echo Job submission done
goto END

echo Starting Job %1
START "Untitled Job %1" /MIN %SCADAPP% --o test_%1.dxf --D zoffset=%1 2Drender.scad
REM Using a timeout of a few seconds can reduce the system load by spreading the invocations.
REM How long will depend on the OpenSCAD startup, and the model complexity.
REM On the test system (4 cores, 8 logical), 10 invocations at 1s gave 100% CPU.
REM Upping the timeout to 10s kept the CPU under 60%, and 1-3 jobs were finishing in the 10s.
REM The overall run time for the set was longer.
REM A 5s timeout kept the peak load under 85-90%, and mostly around 50% for the less complex invocations.
REM timeout 5
goto END


There is also a Dimensional Drawing library linked from the OpenSCAD documentation which provides a method of adding dimensions and documentation boxes in order to create useful engineering drawings.

Execution time

Rendering the STL file is a little faster than starting from a OpenSCAD description file, since the STL contains just the pre-calculated mesh.

Even using the STL file approach, OpenSCAD has to render the object in order to get the 2D projection. This takes some time, especially with complex models. One possibility which may work is to try to launch several instances of OpenSCAD using different cores of the processor. Since OpenSCAD is a single-core application, it should be possible to run two or three instances in parallel. A lot depends on how many cores are available, the load on the system, and if the command shell will allow launching applications in new cores. On Linux, starting a new program instance will normally assign it to whatever core the process manager sees as most available. The same thing happens with the Windows Command shell using START. It is probably wise to limit the parallel processes to one less than the number of cores available, say 3 on a quad-core system. This allows the operating system some head room for housekeeping.

It is also a good idea to consider the amount of available memory. Running too many concurrent processes may overload the available memory, and cause the system to bog down doing memory paging.

However, unless the primary purpose is to generate 2D plans, this process is not likely to be done frequently. Most iterations of the 3D design will not need a 2D set. Only final or stage renditions will need the conversion.

  1. OpenSCAD Programmatic software for creating solid 3D objects ↩︎

  2. DXF - Drawing Exchange Format file. Contains vector information for 2D or 3D drawings. Widely supported by Computer Aided Drawing packages. ↩︎

  3. STL - variously Stereolithography, Standard Triangle Language or Standard Tessellation Language. Text or binary format file containing a triangle mesh that describes the surface of a 3D object. ↩︎