Make a DAT File for LDRAW

by ftking_83702 in Craft > Digital Graphics

10126 Views, 4 Favorites, 0 Comments

Make a DAT File for LDRAW

screen_2.jpg
bb_5.jpg
Orion Pobursky once told me that LDRAW is the poor man's cad program. It is easy to use, released under the open content license, and very popular.

I use LDRAW with MLCAD. MLCAD is the gui interface that sits on LDRAW. Analogous programs such as LEOCAD can access the LDRAW libraries.

There are many unofficial libraries that can work with LDRAW. It is useful to know how to create an original .dat file to build a library that can be used to generate awesome CAD images documenting models! A dat file is a text file that defines an object (such as a LEGO brick).

This ft-ible is a basic introduction to how to create your own library of parts for LDRAW.

DISCLAIMER: This is meant as a very bare bones/general introduction to get things rolling. There is a lot more detail that can be added. I have plans for future ft-ibles covering this information.

There are a number of awesome resources that cover in detail how to use LDRAW and related programs:

*www.ldraw.org (This site is awesome!)
*Tim Courtney et al VIRTUAL LEGO
*Kevin Clague et al LEGO SOFTWARE POWER TOOLS WITH LDRAW, MLCAD AND LPUB
*Anything authored by Orion Pobursky!

*There are an awesome set of LDRAW authoring tools at Philippe Hurbain's website:
http://philohome.com/isecalc/isecalc.htm

In the past I have designed components in a GUI environment such as SolidWorks, and then coverted the files into a LDRAW format. I thought it would be of benefit to everyone to explore how to develop elements directly in the dat format.

WHAT YOU NEED:

measure_1.jpg
LDRAW and MLCAD installed
Working knowledge of LDRAW/MLCAD
Notepad
Measuring tools
Paper and pencil
Manipulative object

NOTE:
Software, instructions, and tutorials can be found at www.ldraw.org These guys are awesome, and deserve your support!

MEASURE AND SKETCH:

sketches_1.jpg
sketches_2.jpg
A LDRAW model is made of vertices, edges and surfaces. Your part-file has to provide one or more commands for each edge and surface. You need to specify these edges and surfaces by the XYZ position of their vertices. So you have to measure out where the vertices are.

I am creating a quick model of a building block. I measured and noted each vertices. During the course of this process, I broke the manip into concrete components.

I came up with 8 basic parts of the building block:
Pin Base
Pin Top
Block Top
Block Base Panel
Block Side Panel
Slot Side 1
Slot Side 2
Slot Top

Each of these basic parts will be integrated into one master file to make up the element. (Note-my final file names differ than these titles).

INTRODUCTION TO LINE TYPES:

measure_1.jpg
A dat file is a text file that defines the object. It is made up of a series of lines that define the edges and shapes of the object.

Specifically, there are six general line types in a LDRAW file. The line type is set by the first number on each entry. The line types are:

0: Comment or META Command
1: Sub-file reference
2: Line
3: Triangle
4: Quadrilateral
5: Optional Line

For example, a line type 2 would might look like:

2 24 -3.75 0 3.75 3.75 0 3.75

The first number is the line type. (In this case it is a straight line with a start and end point). The second number is the color of the line. Then there are two sets of numbers representing the start and end points of the line.

For this introduction, I used just line types 0, 1, and 4. I started with the base of the pin. It is essentially a box measuring about 1mm tall and 3mm on each side.

Since LDRAW uses LDU units, I have to convert 1 and 3 into LDUs.

1/.4 = 2.5 LDU
3/.4 = 7.5 LDU

A LDRAW file generally centers each component on X=0 and Z=0 with the the top of the part set to Y=0. This means I need to divide 7.5 by half. The top of the component will be at Y=0, so I do not need to divide that number.

HINT: I used a spreadsheet program (which I can later export into a txt file) to order the lines. This helps immensely when entering in many data points.

CREATE SUB FILES:

pin_box_1.JPG
screen_1.jpg
The base for the pin looked like:

0 Pin Base
0 Name: pin_box_1.dat
0
0 Top Square Frame
2 24 -3.75 0 3.75 3.75 0 3.75
2 24 3.75 0 3.75 3.75 0 -3.75
2 24 3.75 0 -3.75 -3.75 0 -3.75
2 24 -3.75 0 -3.75 -3.75 0 3.75

0 Bottom Square Frame
2 24 -3.75 2.5 3.75 3.75 2.5 3.75
2 24 3.75 2.5 3.75 3.75 2.5 -3.75
2 24 3.75 2.5 -3.75 -3.75 2.5 -3.75
2 24 -3.75 2.5 -3.75 -3.75 2.5 3.75

0 Four Corner Lines
2 24 -3.75 0 3.75 -3.75 2.5 3.75
2 24 3.75 0 3.75 3.75 2.5 3.75
2 24 3.75 0 -3.75 3.75 2.5 -3.75
2 24 -3.75 0 -3.75 -3.75 2.5 -3.75

0 Quadrilaterals

4 16 -3.75 0 3.75 -3.75 2.5 3.75 3.75 2.5 3.75 3.75 0 3.75
4 16 3.75 0 3.75 3.75 2.5 3.75 3.75 2.5 -3.75 3.75 0 -3.75
4 16 3.75 0 -3.75 3.75 2.5 -3.75 -3.75 2.5 -3.75 -3.75 0 -3.75
4 16 -3.75 0 -3.75 -3.75 2.5 -3.75 -3.75 0 3.75 -3.75 2.5 3.75
0

NOTE: Leave notes in the comments. If there is a problem, it can be found quickly.

GENERAL TIPS:

bb_5.jpg
*LDraw parts are measured in LDraw Units (LDU) Real World Approximation is 1 LDU = .4 mm

*Rule of thumb: Do not sweat features that are smaller than .4 mm.

*LDraw uses a right-handed co-ordinate system where -Y is "up".

*LDRAW standard for positioning each component is to center the piece on X=0 and Z=0. Usually, the top of the part is set to Y=0

*LDRAW use two special color codes: 16 and 24. 16 is a generic color for polygons and 24 is a generic color code for edge lines. In new parts, these two codes are used almost exclusively.

*Be careful of creating cross-ties. (This means ordering the set of vertices in a polygon so that two edges cross each other, forming a shape that looks like a bow-tie). They foul things up.

CREATE MORE SUBFILES:

pin_top_1.JPG
block_top.JPG
block_bot.JPG
block_side.JPG
slot_a.jpg
slot_b.JPG
slot_c.JPG
In this example, I created a series of subfiles documenting the parts of the building block:
Pin Base (pin_box_1.dat)
Pin Top (pin_top_1.dat)
Block Top (block_top.dat)
Block Base Panel (block_bot.dat)
Block Side Panel (block_side.dat)
Slot Side 1 (slot_a.dat)
Slot Side 2 (slot_b.dat)
Slot Top (slot_c.dat)

NOTE: In the file block_top.dat, I included both the top surface of the block and the two sides that are not intersected by the bottom slot.

Example:
0 Block Top
0 Name: block_top.dat
0
0 Top Square Frame
2 24 -18.75 0 18.75 18.75 0 18.75
2 24 18.75 0 18.75 18.75 0 -18.75
2 24 18.75 0 -18.75 -18.75 0 -18.75
2 24 -18.75 0 -18.75 -18.75 0 18.75
0
0 Bottom Side Frame
2 24 -18.75 12.5 18.75 18.75 12.5 18.75
2 24 18.75 12.5 -18.75 -18.75 12.5 -18.75
0
0 Four Corner Lines
2 24 -18.75 0 18.75 -18.75 12.5 18.75
2 24 18.75 0 18.75 18.75 12.5 18.75
2 24 18.75 0 -18.75 18.75 12.5 -18.75
2 24 -18.75 0 -18.75 -18.75 12.5 -18.75
0
0 Quadrilaterals
4 16 -18.75 0 18.75 18.75 0 18.75 18.75 0 -18.75 -18.75 0 -18.75
4 16 -18.75 0 18.75 18.75 0 18.75 -18.75 12.5 18.75 18.75 12.5 18.75
4 16 18.75 0 -18.75 -18.75 0 -18.75 18.75 12.5 -18.75 -18.75 12.5 -18.75
0

MAKE a MASTER FILE:

rmw_block_image.jpg
comparison_block.JPG
To make things easy, I put all the subfiles into the LDRAW/PARTS directory. I added the parts to LDRAW's PARTS.LST so they show up in MLCAD.

NOTE: This process deserves its own instructable. I am assuming a working knowledge of LDRAW/MLCAD.

Organize the parts to form the object. I used MLCAD to do this. This is what the saved file looks like:

0 RMW Building Block
0 Name: RMW_bb5.dat
0 Author: Richard Mussler-Wright
0 Unofficial Model
0 ROTATION CENTER 0 0 0 1 "Custom"
0 ROTATION CONFIG 0 0
1 16 0 0 0 1 0 0 0 1 0 0 0 1 block_top.dat
1 16 0 12.5 -11.1 1 0 0 0 1 0 0 0 1 block_bot.dat
1 16 0 12.5 11.4 1 0 0 0 1 0 0 0 1 block_bot.dat
1 16 0 -2.5 0 1 0 0 0 1 0 0 0 1 pin_box_1.dat
1 16 0 -7.4 0 1 0 0 0 1 0 0 0 1 pin_top_1.dat
1 16 18.7 6.2 0.1 0 -1 0 0 0 -1 1 0 0 block_side.dat
1 16 -18.7 6.3 0 0 -1 0 0 0 -1 1 0 0 block_side.dat
1 16 0 11.2 3.8 -1 0 0 0 0 -1 0 -1 0 slot_a.dat
1 16 0 11.2 -3.7 -1 0 0 0 0 -1 0 -1 0 slot_a.dat
1 16 0 7.5 4.4 -1 0 0 0 -0.258819 -0.965926 0 -0.965926 0.258819 slot_b.dat
1 16 0 7.5 -4.3 -1 0 0 0 -0.258819 0.965926 0 0.965926 0.258819 slot_b.dat
1 16 0.1 4.993 0.195 -1 0 0 0 -1 0 0 0 1 slot_c.dat
0

Save the file. I renamed the file as a .dat, and put it into the LDRAW/PARTS directory, and added it to the LDRAW PARTS.LST. Now I have a Building Block 5 that I can build with in the LDRAW environment!

REPEAT: This is a bare bones introduction. I have simplified or glossed over a number of steps, but I hope that this provides enough information to develop original libraries for LDRAW/MLCAD!

ENJOY!

ft_block-test.jpg
ft_block-testb.jpg
Wow! I can document and animate my cool creations!

MLCAD/LDRAW are very easy to use. I know of libraries for a variety of manipulative systems including LEGO, K'NEX, Lincoln Logs, VEX, and others. It would be awesome for fans to add to the list of libraries!