Tools to Save Your MindStorm Modelsby Jonathan Knudsen
If you've done much work with Lego bricks, you've probably built some models you felt were outstanding -- good enough to save for posterity. You might have wanted to describe how to build the model for other people, or simply to rebuild it yourself some time in the future.
Lego supplies excellent instructions with their sets. These are full color, carefully drawn instructions, usually showing the parts needed for each step and including handy arrows that describe where everything goes. Being an international company, Lego makes the pictures very explicit so they don't rely on a particular language. If you own Lego sets, take some time to appreciate the instructions that Lego provides. They're extremely clear.
What about the rest of us? How can we create Lego building instructions? There are suprisingly good tools available for free on the Internet. Lego enthusiasts form a very strong community on the Internet, and some of them are good programmers too. In this article, I'll describe how you can use several of the available tools to create high-quality building instructions. See the list at the end of this article for links to these tools.
LDraw and LEdit
Figure 1. This screenshot of LDraw shows the arm subassembly from Minerva, a robot from The Unofficial Guide to Lego MindStorms Robots. (click on image to view full size)
Any story about computer-generated building instructions has to begin with LDraw and LEdit. These DOS applications were created by the late James Jessiman in 1996. LEdit is a program for creating model instruction files, while LDraw is the program that displays them. Models are described as a series of steps, and LDraw is capable of showing the model being built, one step at a time.
The next screenshot shows the same model in LEdit. At the top of the screen you can see actual lines from the model file (more on this soon). Within LEdit, you can add parts to a model, remove parts, move and rotate parts, and change the colors of parts. You can also insert markers that signify a complete step.
Figure 2. The same arm subassembly viewed in LEdit. (click on image to view full size)
LEdit and LDraw are good tools, but it takes some time to learn how to use them. LEdit, in particular, has a pretty steep learning curve. The important legacy of LEdit and LDraw is their file format, which we'll examine next.
The DAT file format
LDraw and LEdit models are stored in "DAT files," with a
extension. This file format is the center of most subsequent work in the
Lego modeling software world. No matter what tools you use, you may very
well find yourself staring at a DAT file in a text editor someday, so a
basic understanding of the format is useful.
The file format encompasses two functions:
- part modeling and
- model building.
Figure 3. Image of a two-stud Technic brick and a 2 x 4 plate, the basis for the DAT file.
Individual Lego bricks can be modeled as DAT files by assembling collections of lines and surfaces. DAT files can reference other DAT files, so a complex brick can be built up from simpler pieces. A regular brick DAT file, for example, might reference another DAT file that represents the studs, or bumps, on the brick.
A Lego model DAT file is built by referencing the individual brick DAT files that make up the model. Let's look at a simple example. The model in Figure 3 is built from two bricks
Here's the DAT file for this simple model:
0 Untitled 0 Name: simple.dat 0 Author: MLCad 0 Unofficial Model 1 14 0 0 0 1 0 0 0 1 0 0 0 1 3020.DAT 1 0 0 -24 10 1 0 0 0 1 0 0 0 1 3700.DAT 0
You can pretty much figure it out by looking at it. Every line has a type, which is just a number at the beginning of the line. A 0 indicates a comment line, something that adds information to the DAT file but doesn't add to the model itself. The two important lines begin with a 1, which imports another DAT file into the model. In this case we're using 3020.DAT, the 2 x 4 plate, and 3700.DAT, the two-stud Technic brick with the hole through it. What are all those other numbers on those lines? Those show where the imported part should be placed and how it should be rotated relative to the model.
Complex model files look a lot like this simple one, just with many more "1" lines.
The DAT files for bricks are named according to their part numbers. Most bricks have numbers molded into them; you can see these numbers if you look closely. Over the years, the online Lego community has modeled (that is, created DAT files for) more than 1,500 bricks. If you can't find a brick DAT file, sometimes friendly folks on the Internet will create it for you.
An important extension of the DAT format, the Multiple Part DAT (MPD)
file, allows you to specify multiple subparts inside a single file. For
example, the entire Minerva robot model is represented in a file called
Inside this file, a subassembly called
MinervaArm.dat is defined.
It is used as a component of the entire model.