stl2dat
STL to LDraw converter

New version 1.31 See Version history

stl2dat.zip v1.31
Other downloads
How to use it
Future developpments
Version history
Conversion algorithm
Example
Modeling tips

stl2dat is an utilitary tool to convert .stl files issued from cad software like Solidworks, Autocad, and many others to .dat files for ldraw compatible programs.

It converts triangle facets issued from .STL file to triangle and quad facets, creates type 2 and type 5 lines and inserts standard primitives like cylinder (n-4.cyli.dat) and edges (n-4edge.dat)

Creating parts by hand is interesting, but when you have access to a modern CAD software, it is a little bit annoing. So I looked for a solution to convert CAD software' models to ldraw dat files. I founded the stl format that contains enough information to build a dat file. I could have made a native tool, but this job much more complicated, and it would have only been for a particular software. So I decided to make a tool to convert stl files to dat files.

Note : stl2dat is it intended for use with only Lego elements.

The developpment is still under progress, but the tool can already been used.


Downloads

stl2dat.zip The program itself
Source files Available on sourceforge.net/projects/stl2dat
stl.reg A registry file to set STL parameters for solidworks ( Just double-click on the file to install it )
stl.swb A macro for solidworks to set the STL parameters
32137.dat (68 kb) An example of part generated with stl2dat


How to use it

  1. Create the part with a CAD software.
    Use LDraw Unit, not millimeters. (20 = length of 1x1 brick)

  2. Export the model in stl format. With Solidworks, it is done with the "Save as" command.
    Be sure that stl ascii format is used. (It cannot be done with the macro stl.swb)
    Set the stl parameters. Deviation = 0.1mm, AngleTolerance = 22.5deg.
    The AngleTolerance is important for cylinder primitive detection.
    With solidworks, you have to use stl.swb macro to do this.

  3. Then run stl2dat to translates the file.
    The program must run in a dos window or been started with Start/ Execute program window. (It must run under Windows, even if the program has console interface)
    Try different angle eps values. A good result with options -a 22.51 -eps 0.01

  4. Edit the .dat file to add missing information like comments.
    Add primitives like connector, peg, stud, etc... (This is too complex to do automatically.)

  5. Copy the .dat file to /parts directory and use it with LDraw compatible program.

Tip:

For some parts, it can be usefull to model separate sections of the part, and then to merge the resulting dat files. In this case they are generally unwanted facets in the dat file. Tangent facets are grouped to help remove groups of tangent facets. You can also use -cs option to see the detected surfaces.

Syntax:

Usage : stl2dat filename [options] [name [author]]

-out filename: name of the output file
-o X Y Z
: origin point
-m X Y Z A B C D E F G H I
: transformation matrix
-scale S
: S is scale factor
-scalemm
: units of input file are in mm instead of ldraw units
-a angle
: angle is limit for optional edges (default 22.5 deg)
-aq angle : angle is limit for quadrangles (default 15 deg)
-at angle : angle is limit for remove unusefull facets (default 11.25 deg)
-eps value (default 0.01)
-teps value
: minimum distance for coincidence (default 0.001)
-deps value : maximum determinant for coplanar quads (default 0.1)
-o4 : no merge to quadrangles
-o5 : remove of internal (concave) optional edges
-op : no primitives calculation
-pp : print geometric surfaces
-cn : detect cylinder based on difference between normal of facet and normal of theorical surface
-oe : no creation of edges
-of : no remove of unusefull facets
-np
: no plane geometric surfaces
-nc : no cylinder geometric surfaces
-nt : no tangent geometric surfaces
-c1 color : color of primitives
-c2 color : color of edges
-c3 color : color of triangles
-c4 color : color of quadrangles
-c5 color : color of optional edges
-no1 : no primitives
-no2
: no edges
-no3
: no triangles
-no4
: no quadrangles
-no5
: no optional edges
-cs
: random color for surfaces
-cc : random color for adjacent to cylinder
-dat : produces a .dat file
-ldr
: produces a .ldr file
-nobfc
: no BFC instructions
-silent
: does not display informations
-ldraw : does not add LDraw standard header
-raw : conversion without any optimisation or edge calculation

Examples:

stl2dat mypart.stl -a 22.5 "My first part" "Marc Klein"

stl2dat x000.dat -o 100 100 50 "My part" "My name"

The result is a file named mypart.dat in the same directory than mypart.stl


Future developpments

Ideas for future implementation:


Version history


Conversion algorithm

  1. Scans all the facets to create all the adjadent edges and to keep information about adjadent facets
  2. All tangent facet (with an angle lower a setable limit) are put together in geometric surfaces. Type supported are: plane, cylinder or other tangent surface
  3. Detect cylindric primitives.
  4. Create necessary edges: type 2 and 5 lines.

An example of the result of the conversion

32137.dat (68 kb)

32137 created with Solidworks, converted with stl2dat and rendered with MLCAD


Disclaimer

LEGOŽ is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this site.
Please visit Legos own homepage for futher information.
www.lego.com 

Return to my lego page