• 1
TobyMac

LDraw line images

Question

Offtooic, so I made a new topic.

I'm currently sorting my kids LEGO. I have a lot of containers with parts, that I need to label. Is it possible to render LDraw images like it is a drawing for a coloring book? Example:

30372.png

Quality doesn't have to be high. The labels will be max 3cm high

Share this post


Link to post
Share on other sites

Recommended Posts

  • 0

Check this: Parts Catalogs. Zip contains BrickLabels.pdf, with hundreds of small black/white images, specifically designed for use as labels, and they can be colored. Also included some other part catalogs, all things I found somewhere on the internet during the last ten year, and saved them to a harddisk.

Share this post


Link to post
Share on other sites
  • 0

To be sure, if I remember correctly, stud.io has a wire-frame feature, so you can create a pdf with single part images shown as wire-frames. Might also checkout LeoCAD, if you use part in color white, I think the resulting printed image is a wire-frame.

 

Share this post


Link to post
Share on other sites
  • 0

You can batch-render LDraw parts yourself with LDView. To get a proper, good line look like they also kinda look in LEGO instructions use the following settings:

Tab General:

  • FSAA: 8x or 16x (depending on your hardware you can't choose 16x)
  • Antialiased lines: ON
  • Background color: White
  • Field of view: 0.1

Tab Geometry:

  • Edge Lines: ON
    • High Quality: ON
    • If you want, you can turn Always black ON too. I personally don't.
    • You gotta experiment a bit with Thickness. It's dependent on your final image size what looks best. I generally use the 2nd notch (from the left).

Tab Effects:

  • Lighting: OFF

Tab Primitives:

  • Primitive substitution: ON
  • Curve quality: whatever you like. Since the goal here is small images, it probably doesn't need to be very high but if you're rendering single parts the processing time is probably negligible.
  • Use hi-res primitives when available: ON

-------------

Furthermore, the LDraw -> Blender plugin I linked a week or so ago also has a line option I believe, but not entirely sure about that.

Share this post


Link to post
Share on other sites
  • 0

EDIT: Whoops, I misread the question. I thought it was for singular parts. For a coloring book, I would recommend the same settings is above, except:

  • Always black lines
  • Show edges only

That way you get a white image with black lines:

 

Knipsel.PNG

Share this post


Link to post
Share on other sites
  • 0

EDIT 2: wait a minute. I misread the question the 2nd time. First time was right. I'm tired, I'm going to bed :P

Share this post


Link to post
Share on other sites
  • 0

OK, I have LDView and the LDraw Library. How do I make a bulk render? I've found a .bat script, but that is incomplete (print-screens are half-screen).

Share this post


Link to post
Share on other sites
  • 0
1 hour ago, TobyMac said:

OK, I have LDView and the LDraw Library. How do I make a bulk render? I've found a .bat script, but that is incomplete (print-screens are half-screen).

I never really took a look at the batch feature. I believe it's also pretty new so there might be a lack of documentation and examples. I can take a look when I get home.

Alternatively, you can just create a super basic Python script that runs through all your LDraw parts and calls LDView for every part separately. Should be pretty simple, only a few lines.

Share this post


Link to post
Share on other sites
  • 0

Ok, I made something that goes through ALL your LDraw parts and renders an image for it. The only stuff you need to change are the CAPS variables at the top.
Also note that I tried multi-threading which I've never done in Python. It seems to work, but I'm not sure if it actually makes the thing go faster :P You can define the number of threads yourselfes.

Note that I made this one real quick and there's little testing or optimization of whatever :P

import glob
import subprocess
import threading

LDRAW_PATH = 'C:/Users/Merlijn/LDraw'
LDVIEW_PATH = 'C:/Users/Merlijn/LDraw/Software/LDView/LDView64.exe'
OUTPUT_PATH = 'E:/tmp'
MAX_WIDTH = '200'
MAX_HEIGHT = '200'
PART_COLOR = '0xFFFFFF'  # Color format standard HEX RRGGBB
THREADS = 1


def create_chunks(seq, num):
    avg = len(seq) / float(num)
    out = []
    last = 0.0

    while last < len(seq):
        out.append(seq[int(last):int(last + avg)])
        last += avg

    return out


def worker(paths):
    for path in paths:
        part_number = path.rsplit('\\', 1)[1].rsplit('.', 1)[0]
        print(part_number)

        subprocess.call([
            LDVIEW_PATH,
            '-AutoCrop=1',
            '-SaveWidth={}'.format(MAX_WIDTH),
            '-SaveHEIGHT={}'.format(MAX_HEIGHT),
            '-DefaultColor3={}'.format(PART_COLOR),
            '-SaveSnapShot={}/{}.png'.format(OUTPUT_PATH, part_number),
            path
        ])


def main():
    ldraw_part_paths = glob.glob(LDRAW_PATH + '/parts/*.dat')
    chunks = create_chunks(ldraw_part_paths, THREADS)

    threads = []
    for i in range(THREADS):
        t = threading.Thread(target=worker, args=(chunks[i],))
        threads.append(t)

    for thread in threads:
        print('starting thread')
        thread.start()


main()

 

Share this post


Link to post
Share on other sites
  • 0
20 minutes ago, legolijntje said:

LDRAW_PATH = 'C:/Users/Merlijn/LDraw'

To save time, I could drop all .dat files from which I need an image (only 100 or so) from LDraw in a different folder and change to that path in this line?

Share this post


Link to post
Share on other sites
  • 0
54 minutes ago, TobyMac said:

To save time, I could drop all .dat files from which I need an image (only 100 or so) from LDraw in a different folder and change to that path in this line?

Yeah, I suppose you could :)

Share this post


Link to post
Share on other sites
  • 0

Toby, if you get this working, please share your experiences. I looked into LDView when trying to bulk-render RB's LDraw images, and ran into some problems. Firstly, LDView can be ran in batch, but you can't set parameters from the command line, so it always seems to use your default preferences. Secondly, and more importantly, according to the docs I read, LDView returns control *before* the image is rendered and stored. Than might mean that if you create a batch to render 1,000 images, you have a possible memory leak, as the next instance of LDView is started before the previous instance has ended. Of course, you could build in a wait for 30 seconds or so, but with 70,000 images that wouldn't work. Also, in Linux, each instance takes about 10 seconds to initialize, and that alone (for 70,000 images) was a problem for me.

Looking forward to hear your results...

Share this post


Link to post
Share on other sites
  • 0

Guys, I think this could be interesting to regular forum users, and I could move the thread to the Help Forum. Obviously, if you want to continue privately (just us), that is OK too. Just thought I'd mention it.

Share this post


Link to post
Share on other sites
  • 0
1 minute ago, Simon said:

Guys, I think this could be interesting to regular forum users, and I could move the thread to the Help Forum. Obviously, if you want to continue privately (just us), that is OK too. Just thought I'd mention it.

Ok. When it works I'm planning to post in some facebook groups as well. This question comes along often. Anyway I can credit you there?

Share this post


Link to post
Share on other sites
  • 0

Nah, don't need credit, and I hate Facebook (and LinkedIn, and WhatsApp and all the other unsocial media) -smile-

Share this post


Link to post
Share on other sites
  • 0

I'm getting these errors:

Quote

Traceback (most recent call last):
  File "C:/Users/Eigenaar/AppData/Local/Programs/Python/Python36/LDRAW_Conversion.py", line 56, in <module>
    main()
  File "C:/Users/Eigenaar/AppData/Local/Programs/Python/Python36/LDRAW_Conversion.py", line 48, in main
    t = threading.Thread(target=worker, args=(chunks,))
IndexError: list index out of range

 If I remove the main() at the end of the script, I get no errors, but nothing is happening.

Shell says:
 

Quote

Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 
 RESTART: C:/Users/Eigenaar/AppData/Local/Programs/Python/Python36/LDRAW_Conversion.py 
>>> 

 

Share this post


Link to post
Share on other sites
  • 0
On 10/29/2018 at 4:38 PM, Simon said:

but you can't set parameters from the command line

You certainly can. Not sure if you can set all options through parameters, but there's always the option to pass your own .ini file with parameters which can include any setting.

On 10/29/2018 at 7:16 PM, TobyMac said:

I'm getting these errors

Ugh, no idea why. I shouldn't have included those threading stuff without having used it before :P

Try this one without any multi-processing:

import glob
import subprocess

LDRAW_PATH = 'C:/Users/Merlijn/LDraw'
LDVIEW_PATH = 'C:/Users/Merlijn/LDraw/Software/LDView/LDView64.exe'
OUTPUT_PATH = 'E:/tmp'
MAX_WIDTH = '200'
MAX_HEIGHT = '200'
PART_COLOR = '0xFFFFFF'  # Color format standard HEX RRGGBB


def main():
    ldraw_part_paths = glob.glob(LDRAW_PATH + '/parts/*.dat')

    for path in ldraw_part_paths:
        part_number = path.rsplit('\\', 1)[1].rsplit('.', 1)[0]
        print(part_number)

        subprocess.call([
            LDVIEW_PATH,
            '-AutoCrop=1',
            '-SaveWidth={}'.format(MAX_WIDTH),
            '-SaveHEIGHT={}'.format(MAX_HEIGHT),
            '-DefaultColor3={}'.format(PART_COLOR),
            '-SaveSnapShot={}/{}.png'.format(OUTPUT_PATH, part_number),
            path
        ])


main()

I think LDView's own batch feature is probably better than such a script anyway, but I couldn't quickly find its documentation :P 

Share this post


Link to post
Share on other sites
  • 0
21 minutes ago, TobyMac said:

It works! Awesome!!!!!!!

takes about 3 seconds per part (standard bricks). Is it also ok with you if I share this?

Some examples:
https://www.bricksafe.com/pages/TobyMac/div/ldview

Nice!

It does about 2-3 parts per second for me :huh:
Btw, if you want a little 'rounder' studs you should up the curve quality in LDView a bit.

Feel free to share it, no problem, but note that it's untested and optimized code. Like I said, the best idea is probably to use LDView's builtin batch functionality ;) 

Share this post


Link to post
Share on other sites
  • 0

I have the program running for all 11,000+ files. When done I'll upload them to bricksafe. I keep getting run time errors for LDView, but it still works.
Next on the list is making the labels. I have over 200 boxes, so I'll see if I can get that automated with some php script. Enter the partnumber and a label comes out in printable format

Share this post


Link to post
Share on other sites
  • 0

Nice for the casual collectors out there, personally I need mine in color. So I usually pick that right of the part page and scale it to the storage container size.

Share this post


Link to post
Share on other sites
  • 0
6 minutes ago, biodreamer said:

Nice for the casual collectors out there, personally I need mine in color. So I usually pick that right of the part page and scale it to the storage container size.

I have most parts not sorted on color, simply because I don't have enough room for a separate container for each color.
There is also a download here on rebrickable where you can download all parts from a specific color in 1 download-file.

Share this post


Link to post
Share on other sites
  • 0

Wanted to show of the end result. It's been a tiring job, but I'm pleased with the result. Now to see how long it stays organized with 3 little children in the house (and it is their LEGO).

IMG_20181122_202351.jpg

IMG_20181122_202413.jpg

IMG_20181122_202430.jpg

Share this post


Link to post
Share on other sites
  • 0

Very impressive! I really like that you put Dutch descriptions on each of the stickers! Those were not in the download above, were they?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now