Producing Complex Structures on the EV3DPrinter

So, for the past few weeks I’ve been working on my build of the EV3DPrinter. I’ve had it printing various geometric shapes, “College” letters, and more recently I’ve been working on a complex shape – namely a castle:

A Small Castle
A Small Castle


Since I’ve been programming my instance of the EV3DPrinter in EV3G I couldn’t realistically use G-Code as the string handling in EV3G isn’t up to the task. Instead I would do it some other way.

For years I’ve been using a very old X11 drawing package Tgif; this has the great advantage that its file format is text based, and object oriented – a perfect source of drawing data. I used this package to draw out my letters:

Letters in Tgif
Letters in Tgif

This worked perfectly as it was easy to convert the polygon path of each letter in to a simple set of coordinates for use in my code on the printer. I was however accidentally fortunate in that I’d aligned the letters to a grid, so could work out which one was which based on rows and then position along that row.

When it came to making the castle I figured I’d use the same program to develop each layer, and just write a new Perl program to parse the file into plot data. It was rather more complex than I’d thought. I had to design each and every layer of PLA, bar those layers that repeated, i.e. the first 5. So, first, I started off with just the base of the windows:

Base of the castle’s windows

This took two goes as the first time I had the slope at the bottom at too shallow an angle, so they sagged badly. Next I worked my way up the walls:

Working out the walls

Eventually after some trial I got to the final castle.

Process – First Version

The luck I’d had with the letters couldn’t work with a complex object. I needed to be able to define a layer’s polygon, its position relative to the layer below and some form of order. The simple answer, for me, in Tgif was to have a bounding box, a text object with a number, and a polygon inside the bounding box, as below:

Layer 27 of the castle

Layer 27, above, is closing up the tops of all the windows and the doorway, along with producing buttresses for the crenelations at the front. So here, there is the box, the number “27” and a polygon – the just visible arrow on the inside bottom left defines the end point of the path for that layer. The line width of the polygon defines how many layers are to be repeated for this path – 1 in this case.

This was a time consuming process, which did work, but resulted in 42 layers. The final Tgif image looked as below:

Final Tgif file for the castle

Process – Second Version

Although the Tgif images, so far worked well, it was a lot of effort. Discussing with a colleague, he asked why I couldn’t define a start and an end and layer-by-layer go from one to the other. A bit of thinking and a new plan came to mind.

The same system of box, text, and polygon would be used by a way of linking a start and an end would be used – a simple dotted box would group two layers together. The layer numbers would define the start and end, and all layers between would be interpolated between the two polygons. Of course both polygons would need the same number of points, but that’s fine.

Some new coding, along with spotting a mistake in my first castle, and I get the new Tgif image of:

13 layers to define the castle
Close up on layers 22 – 27

This is so much easier to manage. I’m now thinking on what to make next. I’ll be writing another program that will be able to read in multiple complex models and give a menu to select what to make. Once that’s done, I think I’ll be ready to publish my code – watch this space.

Text per-page for LPub4

LPub4 offers a way to add text to a page, but no option for text to appear on every page. Whilst working on the BIs for the DuckToppl3r I had a need to put a disclaimer on each page. I am lead to believe that LPub3D can do this, but that is currently a Windows-only program. Since LDraw and LPub4 use text and I’m no stranger to Perl I figured a quick script would come to my rescue 🙂

LPub4 produces a new page on each STEP or ROTSTEP statement when not in a multi-step page, or on a “MULTI_STEP END” statement. So, all I needed to was to output the same “INSERT TEXT” statement above one of those three where relevant. The code used is as below if this proves to be useful to anyone:


use Getopt::Long;

$first = 'The MINDSTORMS® Community Partners present ROBOTREMIX3 [31313 + 42050] Community Challenge 2016. DUCK TOPPL3R Design & Building Instructions by Jerry Nicholls.';
$second = 'MINDSTORMS is a registered trademark of The LEGO Group. This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. August 2016';

GetOptions( 'first=s' => \$first, 'second=s' => \$second );

$multi = 0;
while(<>) {
 $multi = 1 if /MULTI_STEP\s+BEGIN/;

 if ((!$multi && /^0\s+(?:ROT)?STEP\s/) ||
     (/MULTI_STEP\s+END/)) {
     $multi = 0;
     print <<"TEXT";
0 !LPUB INSERT TEXT "$first" "Helvetica,18,-1,5,75,0,0,0,0,0" "Black" OFFSET 0.06 0.935
0 !LPUB INSERT TEXT "$second" "Helvetica,18,-1,5,75,0,0,0,0,0" "Black" OFFSET 0.06 0.95