Generating labels for Lego drawers

tl;dr: use the script below to generate thousands of labels.

Once the number of drawers for sorting Lego bricks increases, it becomes necessary to label them properly. I wanted a simple label with a clean representation of the type of brick inside. On this site, there is a script available to generate labels targeted at some specific label printers. However this was really targeted for the label printer and to run on Windows computer. I needed something to run on linux (Debian in my case) and to generate just simple images.

Parts library: LDraw

First you need the models for the lego parts library:

sudo apt-get install ldraw-parts

All the files as .dat are installed under /usr/share/ldraw/parts

Renderer: LDView

Then you need the ldview renderer. You can install one of the package available on the  ldview site (4.3 worked for me). Or if you prefer you can build your own Debian package from the source:

# Retrieve the source
git clone https://github.com/tcobbs/ldview
# Build the package
cd ldview/QT
./makeall
./makedeb
# Install the package
sudo dpkg -i ldview-4.3-debian-jessie.amd64.deb

Then you have /usr/bin/LDView available.

Putting it together

After that, adapting the script to run on linux was pretty straightforward:

#!/bin/bash

GENERAL_PARAMS="-Antialias=0 -LineSmoothing=0 -TransDefaultColor=0 -DefaultColor3=0xFFFFFF -BackgroundColor3=0xFFFFFF -ProcessLDConfig=1 -MemoryUsage=2"

GEOMETRY_PARAMS="-Seams=1 -SeamWidth=50 -BoundingBoxesOnly-0 -Wireframe=0 -RemoveHiddenLines=0 -WireframeFog=0 -WireframeThickness=5 -BFC=0 -ShowHighlightLines=1 -EdgesOnly=0 -ConditionalHighlights=1 -ShowAllType5=0 -ShowType5ControlPoints=0 -PolygonOffset=1 -BlackHighlights=1 -EdgeThickness=5"

EFFECTS_PARAMS="-Lighting=1 -UseQualityLighting=1 -SubduedLighting=0 -UseSpecular=1 -OneLight=0 -LightVector=-1,1,1 -OptionalStandardLight=1 -DrawLightDats=1 -NoLightGeom=0 -StereoMode=0 -CutawayMode=0 -SortTransparent=1 -UseStipple=0 -UseFlatShading=0 -PerformSmoothing=1"

PRIMITIVES_PARAMS="-AllowPrimitiveSubstitution=1 -TextureStuds=0 -HiResPrimitive=1 -UseQualityStuds=1 -CurveQuality=12 -TextureFilterType=9984"

SAVE_PARAMS="-AutoCrop=1 -ModelSize=500 -SaveActualSize=0 -SaveZoomToFit=0 -SaveWidth=2000 -SaveHeight=2000 -IgnorePBuffer=0 -SaveAlpha=1"

PARAMS="${GENERAL_PARAMS} ${GEOMETRY_PARAMS} ${EFFECTS_PARAMS} ${PRIMITIVES_PARAMS} ${SAVE_PARAMS}"

PERSPECTIVE270="-FOV=0.1 -DefaultZoom=0.95 -DefaultMatrix=-0.5,0,-0.866025,-0.496732,0.819152,0.286788,0.709407,0.573576,-0.409576"
FILES="/usr/share/ldraw/parts/*"

for f in $FILES
do
  ff=$(basename $f)
  im=${ff/dat/png}
  echo "Processing $f into $im"
  /usr/bin/LDView $f -SaveSnapshot=output/$im ${PARAMS} ${PERSPECTIVE270}
done

Output

So you end up with a few (8000+) images in the output subdir, for example:

 3008 3004
 3660 3659
 3738 44772
 60470  15673

The images are very clean, and crisp, making is easy to identify the right drawer with just a glance.

Here is a list of the 100 most common lego pieces with their label.

6 thoughts on “Generating labels for Lego drawers

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.