LDCad is a great tool for designing LEGO sets. One powerful feature is it’s ability to create part listings from LEGO set inventories. This allows you to build using exactly the set of parts provided in an official LEGO set. I wrote a python tool that will create the necessary files for LDCad to install custom part bins in LDCad on Windows and Linux.

LDCad part bins allow you to group related parts together. This feature is very useful if you want to work from a fixed set of parts such as an existing official LEGO set. But creating custom LDCad part bins is a very manual task – so I wrote a python script to automate everything!

Pass this tool the set number you want and it will connect to Brickset, download the part inventory, convert it into LDCad part bin format and even download an image file for the official set too. As a convenience it will install the files into your LDCad directory, or you can do this manually.

Requirements

  • Obviously you’ll need to download LDCad first and install it!
  • You’ll need python 2.7 installed.
  • Converting the set image to the PNG format required by LDCad requires the Python Pillow library. If you’ve already installed Python then you can use the Python module installer pip to install Pillow.
  • An internet connection to contact Brickset.com and download the inventory files.

Installation

Step 1: Install and start LDCad (if you haven’t already).

Step 2: Be sure to quit LDCad.

Step 3 (optional): Install the Python Pillow module.

Open a command terminal and type

pip install pillow

Example output on Windows:

C:\Python27\Scripts>pip install pillow 
Collecting pillow 
Downloading Pillow-4.1.1-cp27-cp27m-win_amd64.whl (1.4MB) 100% 
Collecting olefile (from pillow) 
Downloading olefile-0.44.zip (74kB) 100% 
Installing collected packages: olefile, pillow 
Running setup.py install for olefile ... done 
Successfully installed olefile-0.44 pillow-4.1.1

On Linux systems:  
sudo -H pip install pillow

Step 4: Download partbincreator.py and lego_colours.py

Save these files into a folder anywhere on your computer. partbincreator.py is the main file, and lego_colours.py is a table mapping LEGO colour names from Brickset to Ldraw colour codes. Don’t even try to read it!

Download link here.

Step 5: Run the part bin creator tool

I find the command line works best for running python tools, as this one takes command line arguments. At a minimum you should supply the set number you’d like to download. For example, to download the LEGO Mindstorms EV3 parts list, use 31313-1 as the set number. Note the ‘-1’ is important, as this is how Brickset indexes sets.

python partbincreator.py 31313-1

Step 6: (Linux only) Install the part bin files into LDCad

If you want to install the files into LDCad automatically type:

python partbincreator.py -i ~/LDCad-1-6-Beta-2a-Linux 31313-1

Alternatively you can copy the two files into LDCad partbins manuallly:

cp 31313-1.* ~/LDCad-1-6-Beta-2a-Linux/partBin/default/sets

Step 6: Restart LDCad

Launch LDCad and then navigate to the custom part bins and you should see the inventory for the EV3 set along with an image for it.

Optional arguments

  • -v enables verbose mode and lets you see what the tool is doing
  • -c allows you to specify a local CSV file containing a list of parts. You could use this option if you’ve created your own local set inventory in a CSV file and would prefer to use it. If a local CSV file is specified the tool will not connect to Brickset.
  • -s skips downloading an image for the set. If you have a local image you can use that instead.
  • -o writes the output to the given file name. By default output is written to <setnumber>.pbg
  • -h prints helpful help text.
  • -i attempts to install the .pbg and .png files into your LDCad installation directory. This has only been tested on Linux so far. You need to pass the install location of LDCad.

Example usage

Download the Bucket Wheel Excavator inventory and set image verbosely:

python partbincreator.py -v 42055-1

 

As above, but write the output to a different filename:

python partbincreator.py -v -o bwe.pbg 42055-1

 

Use a local CSV file specifying the parts to add into the part bin. Will not download an image file. Write the output to a specified filename. Set number is not as important, but still required.

python partbincreator.py -v -c myinventory.csv -o myinventory.pbg 12345-1

 

Download the inventory for the Mindstorms set, but don’t download an image file:

python partbincreator.py -s 31313-1