Build LEGO models with LDraw and LeoCAD
Tutorial – LDraw and LeoCAD
LDraw and LeoCAD help you become a virtual LEGO architect.
For decades, young and old alike have enjoyed the well-known bricks by Danish toy manufacturer LEGO. The success story began in 1932 with wooden toys. In 1949 the first plastic bricks went into production, and since 1958 they have been available in the form that remains popular. Today, LEGO is far more than just a children's toy; there are also many adult LEGO fans. LDraw and LeoCAD help you plan your own LEGO models on your PC.
Before you get started, there are two things you need to do. First, install LDraw [1] on your system. This is an open standard for LEGO CAD programs. The tool comes with 3D models of the bricks and a file format for the notation of the models you build with the bricks. Download the complete brick list [2] and unzip the ZIP file to the ~/ldraw/
folder or another directory. The bricks included in LDraw are constantly updated.
The second step is to install a LEGO CAD program, which you use to turn the virtual bricks into digital models. Of the various programs that use the LDraw standard [3], we chose the current 21.06 version of LeoCAD [4] for this article. For the sake of simplicity, it is a good idea to download the AppImage variant [5], which you can launch directly without installing. Alternatively, pick up the source code from GitHub and compile the program yourself [6].
Digital Bricks
LDraw provides information about the available LEGO bricks and the models, while LeoCAD displays them graphically and lets you edit them. LDraw stores the information in simple text files: .dat
files describe the individual bricks. They are located in the ~/ldraw/parts/
directory or in the parts/
folder in the path in which you unpacked the LDraw archive. For each brick there is a separate file, each with the part number.
In the models/
subdirectory, you will find two examples of models in LDraw: a rudimentary pyramid and a car. Files with models end with .ldr
. Listing 1 shows an example. The first three lines contain the title, file name, and author's name. Each line starting with a 1 represents a brick. The number following it determines the color of the brick, and the remaining numbers indicate the position and rotation. At the end of each line there is the file with information about the brick in question. The individual steps for assembling a model are separated by lines containing 0 STEP
. This means that a model can be described in a simple text file.
Listing 1
Tux.ldr
0 Tux 0 Name: Tux.ldr 0 Author: Daniel Tibi 1 14 -10 -8 -10 1 0 0 0 1 0 0 0 1 49673.dat 1 14 10 -8 -10 1 0 0 0 1 0 0 0 1 49673.dat 1 0 0 -8 10 1 0 0 0 1 0 0 0 1 28653.dat 0 STEP 1 0 0 -16 0 1 0 0 0 1 0 0 0 1 3022.dat 0 STEP 1 15 0 -40 -10 1 0 0 0 1 0 0 0 1 3660b.dat 1 0 0 -40 10 -1 0 0 0 1 0 0 0 -1 6227.dat 0 STEP 1 15 0 -48 -20 1 0 0 0 1 0 0 0 1 94148.dat 1 0 0 -48 10 1 0 0 0 1 0 0 0 1 28653.dat 0 STEP 1 0 10 -72 10 0 0 -1 0 1 0 1 0 0 4286.dat 1 0 -10 -72 10 0 0 1 0 1 0 -1 0 0 4286.dat 0 STEP 1 15 0 -72 -10 1 0 0 0 1 0 0 0 1 6227.dat 0 STEP 1 0 0 -80 0 1 0 0 0 1 0 0 0 1 94148.dat 0 STEP 1 14 0 -88 -20 1 0 0 0 1 0 0 0 1 33909.dat 1 0 0 -88 10 1 0 0 0 1 0 0 0 1 6225.dat 0 STEP 1 0 0 -112 10 1 0 0 0 1 0 0 0 1 3004.dat 0 STEP 1 0 -10 -112 -10 1 0 0 0 1 0 0 0 1 4070.dat 1 0 10 -112 -10 1 0 0 0 1 0 0 0 1 4070.dat 0 STEP 1 15 -10 -100 -22 0.866025 0 -0.5 -0.5 0 -0.866025 0 1 0 10238.dat 1 15 10 -100 -22 0.866026 0 -0.5 -0.5 0 -0.866026 0 1 0 10238.dat 0 STEP 1 0 0 -120 0 1 0 0 0 1 0 0 0 1 3068b.dat
If you just entered the models in files as abstract numeric sequences, the build would not be much fun. This is where LeoCAD comes in. It outputs the models graphically and lets you edit your creations. This is how the model in Figure 1 was created from the text file in Listing 1.
Virtual Building Fun
When you launch LeoCAD for the first time, it needs information on where the LDraw files for each LEGO brick are stored. LeoCAD itself comes with a small selection of bricks, but this would severely limit your creativity. In the View | Settings menu, open a dialog and go to the General tab. Then, in the Parts Library field, enter the path to the folder where you previously unzipped the LDraw files, for example, ~/ldraw/
.
Now you get started with the virtual build. Below the menubar and toolbar, the LeoCAD window is divided into two areas. On the left you will find what is initially an empty base plate. The plate grows automatically as soon as you place bricks close to one of its edges. Top right you will see a ball that you can rotate with the mouse. This lets you move the model in any direction to view it from all sides. Pressing H switches back to the original view. You can press +
to zoom into the model and -
to zoom out.
On the right side of the window, LeoCAD displays a list of all available bricks at the top, followed by an overview of all colors underneath. For a better overview, simply filter the selection. At startup time, the filter defaults to Brick. You can search for bricks using the search field below. Either type in the part number you are looking for (e.g.,, 3002 for a brick with two-by-two studs) or search for the size of a brick. To do this, enter something like 2 x 2. Pay attention to the spaces; otherwise you will not see any results. In addition, you can find a specific brick by typing its name, such as slope brick. Use Insert to integrate the appropriate brick into the model or drag it to the desired position with the mouse.
Now you need to insert the brick correctly. To do this, click on the brick to select it. LeoCAD marks the selected brick with six arrows (Figure 2). The three straight arrows let you move the brick back and forth, left and right, and up and down. Alternatively, you can use the arrow keys and the Page Up and Page Down keys. The three curved arrows are used to rotate the brick on all three axes. To do this, use the same keys as you used for moving again, but this time in combination with the Shift key.
During a build, you will often use single bricks or a certain arrangement several times. Instead of reinstalling and aligning each brick individually, you can simply select the brick in question (or the respective combination if you hold down Ctrl) in the model and then duplicate the selection using Ctrl+D. Then move the cloned elements to the desired location.
Up to this point, your model is still gray – high time to add some color. You can see the available colors bottom right in the window. As soon as you click on one of the colors, the bricks in the selection list on the right are painted in that color. If you want to color bricks that have already been installed, first select the desired color and then select the bricks in question. Then select the Part | Paint Selected menu item to finally color the bricks.
Build Instructions
If you want to rebuild your virtual model later with real bricks, it makes sense to follow the step-by-step instructions. To do this, insert a new build step at appropriate points when assembling the virtual model by pressing Alt+Right arrow. The File | Instructions menu item displays detailed instructions for the finished model, recording the bricks required for each step of the build (Figure 3).
A list of all bricks used in a model is provided by the Parts Used tab from the Submodel | Properties menu item (Figure 4). Switch to the Summary tab and you will see the size of the model. This gives you an idea of the dimensions the model will have when built with real bricks.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
System76 Refreshes Meerkat Mini PC
If you're looking for a small form factor PC powered by Linux, System76 has exactly what you need in the Meerkat mini PC.
-
Gnome 48 Alpha Ready for Testing
The latest Gnome desktop alpha is now available with plenty of new features and improvements.
-
Wine 10 Includes Plenty to Excite Users
With its latest release, Wine has the usual crop of bug fixes and improvements, along with some exciting new features.
-
Linux Kernel 6.13 Offers Improvements for AMD/Apple Users
The latest Linux kernel is now available, and it includes plenty of improvements, especially for those who use AMD or Apple-based systems.
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.