LEGO Importer, Sky Ranger

I’ve been typing up on a simple LDraw file format importer at https://jesterking.github.io/rhildraw

Here are some results

And a recording of the import progressing

The model is the Sky Ranger, set 8836-1. The LDraw model file is by Max Martin Richter, you can find the file at LDraw.org Official Model Repository - Sky Ranger.

The script is still very rough, and with the progression shown it is actually pretty slow. You can turn off the redraws and set zoom_extents to False to have it import much faster. What it does:

  • import parts as block definitions
  • create the assemblies and model from block definitions
  • add materials based on LDraw color definitions

There is still lots to do, but I thought it’d be nice to share the progress so far.

31 Likes

I had exactly this as a kid.

I used 885-1 by Willy Tschager when prototyping the script. I remember playing this as a small boy, I believe it was my uncle’s

Great memories.

5 Likes

Great work Nathan!

Is this the github pages project link you meant to post?:

https://jesterking.github.io/rhildraw/

Indeed it is, I typoed hard there. Fixed in OP. Thanks!

for the dumb kids like me… how do you use this?

@theoutside pick the parts library here:
LDraw.org Library Updates (I chose model complete.zip)

then in the script set your path to where you store the parts
(around line 435):

###########################################
## Set path to where your LDraw library and
## model files are. They should be under
## the same main folder
## Use always forward slashes, also for
## folders on Windows
###########################################
lib_path = "/Users/gijsdezwart/Documents/ldraw"

then a bit lower you will find:

###########################################

## Specify what model to load. Use just the

## file name (including extension)

###########################################

fl : Path = vfiles["10252-1.mpd"]

copy the files you download to the same folder you unzipped to

all the sets are found here LDraw.org Official Model Repository - Model List

2 Likes

In the coming days the script will be improved with configuration capabilities and a simple GUI to do so. Until then these instructions by @Gijs should be good.

I usually use a timer for the redraw like this:
(partly pseudo code since I am logging off.)

import time
startTime = time.time()
for i in range(number_of_things_to_do):
    # REDRAW every 0.2 seconds
    if time.time()-startTime >0.2:
        REDRAW (I use sc.doc.views.redraw since it is much faster than rs.redraw)
        #reset timer
        startTime = time.time()

I do the same thing with counting and presenting % of stuff done too, since I don’t want prompting to slow down fast stuff.

1 Like

:star_struck: :star_struck: :star_struck:

This is :fire:!

You’re converting the native LDraw file format to 3dm, correct?

I just recently started looking at this too and, from a non-coding workflow, it seem like most people use something like these links to open LDR files:

LDView (tcobbs.github.io)
Mecabricks.com

And then export as STL to use Blender for rendering, but I’ve never done it so I’m not sure how much native LDR info gets lost (probably most of it which is the point of creating a script…).

Also I’m pretty familiar with Studio for custom builds which, if you didn’t know already, can export LDR files. Studio files are IO format but there is not really a database of built sets like LDraw. You can import all the parts for a set into Studio but it then needs to be rebuilt digitally.

Studio Download [BrickLink]

Most MOCs that people are giving away or selling nowadays are in .io format on sites like Rebrickable.

Home | Rebrickable - Build with LEGO

The Studio software is maintained and distributed by Bricklink which is a company that was acquired by The LEGO Group (TLG) in 2019.

While there is no “officially” recognized LEGO digital software, TLG buying Bricklink was essentially the nail in the coffin for LDraw software development and it is now no longer actively supported.

LDraw vs Studio vs MecaBricks (online based) for modeling and generating instructions used to be a common debate but Studio has pretty much won the war.

But, of course, the IO file format doesn’t seem to be as open source as LDR.

P.S. The out-of-the-box Studio rendering capabilities aren’t too bad either!

It has a default setting to automatically add LEGO embossed text to each stud (zoom-in).

Final thought: The flex cable for the wing flaps aren’t in the model for some reason!

It looks like no one ever modeled the part!

I am indeed directly importing the LDraw format. The fileformat describes simple mesh geometry through the .dat files and (sub)assemblies are typically built out of .dat load commands in .ldr files. Full models are typically expressed in .mpd files.

With the way I have set the importer up the goal is to eventually have a library of 3dm files for high quality parts and swap those out for the original mesh-based parts.

Will be fun to add that when I get to do the export side of this :slight_smile:

Perhaps I’ll have to look into that eventually.

This is the “build it yourself” option when I import official LEGO sets into Studio that aren’t an assembled LDR model.

Bricklink inventories the parts for every set number, but that’s it.

Long story short, it’s hard to find new sets already built but a lot of older LDR ones do exist.

The .io files look to be password locked zip-files, so importing those directly is not going to be an option. But you can export from Studio to .mpd or .ldr and load that subsequently in Rhino. Here the Cougar example model that comes with Studio (blue disk added by me).

I suppose it is up to the community to build the sets and export them as MPD and LDR files so they can be brought into Rhino :slight_smile:

3 Likes

I have to issue a correction - the design software that is no longer supported was called LEGO Digital Designer (LDD). It used the LDraw file format.

Yeah, a lot of older models can be found online but not so much with any of the newer ones. There is also an issue with support for the parts library since new parts are constantly appearing and only the Studio library is regularly updated.

This nice thing about Studio is that it is integrated with Bricklink (a marketplace for LEGO parts, among other things) so you can get real time market prices for any MOC you create (plus warnings about parts that may not be available in certain colors) and then buy the pieces from a network of worldwide 3rd party sellers.

If you’re interested in the Studio render capabilities, this was a blog post on how to customize settings, but otherwise the interface is very black box.

Hacking Studio: How To Get Better Lighting in BrickLink Studio Renders - BrickNerd - All things LEGO and the LEGO fan community

Are you just using the Artic display setting in your orthographic viewports? That could make for some cool graphics.

It is the Monochrome display mode in Rhino 8. I think this mode with flat shaded materials would be great.