Local Installation

Install the MachineBlocks LEGO® compatible STL Generator on your local computer
Install OpenSCAD
OpenSCAD is software for creating solid 3D CAD objects. It is free software and available for Linux/UNIX, MS Windows and Mac OS X. Visit openscad.org to download the latest version.
Visit Website

Download MachineBlocks Library

The free MachineBlocks OpenSCAD library provides you with SCAD scripts for creating 3D printable STL models of LEGO compatible bricks and enclosures. You can either clone or fork the GitHub repository or download a ZIP archive with the latest snapshot of the library.
Clone / Fork Repository
The MachineBlocks OpenSCAD library is available on GitHub.
Download Latest Version
Download the latest version as ZIP archive.
Regardless of whether you have cloned the repository or downloaded the ZIP archive, you should find a machineblocks folder containing at least the following subfolders:
machineblocks/
Subfolder Description
examples A collection of SCAD scripts to generate standard LEGO and LEGO Technic bricks.
lib The MachineBlocks OpenSCAD library

Open Example File

Let's start with printing a classic 4x2 LEGO brick. Open the file examples/classic/brick-4x2.scad with OpenSCAD. You should see the following:
A model for a 3D printed LEGO brick in OpenSCAD

Render and Export

Before we can export the model as STL file we need to render the scene. Press F6 or click Design -> Render in the menu. Depending on your computer this can take a while.
The model for the 3D printed LEGO brick is rendered in OpenSCAD
Now that we have rendered the scene, we can export the model as STL file by pressing F7 or clicking File -> Export -> Export as STL ... in the menu.
The model for the 3D printed LEGO brick is exported from OpenSCAD as an STL file
LEGO, LEGO Technic, the LEGO logo and the Minifigure are trademarks of the LEGO Group. MachineBlocks is not affiliated with or sponsored by the LEGO Group.