Thursday, January 16, 2014

3D Editing the Hard Way

Last spring I was digging around Thingiverse, looking for cool things to print, and came across Dizingof's version of a Klein bottle. It was good timing; a week later he decided to remove all his models from the site, but it was also at a point in my 3D printing experience where such a complex print seemed far too difficult.

In the intervening months, the file sat on my hard drive, up until this week when I finally decided that we'd done enough printing, tuning and fixing to attempt it. I fired up Slic3r, tweaked the config a little to drop down to 0.2 mm layers for all the fine details, and exported the file. This took some time. The result was a 34.5 MB file; I uploaded it to the OctoPrint instance controlling the printer, crossed my fingers, and pressed Print.

The initial result was disappointing. I watched the printer make something that looked very much like this:


The solid line is a double skirt, which simply gives the extruder time to start extruding (double because this printer has a Bowden tube, so it tends to drool a bit while heating up). The little blue dots are the beginning of the print, but they're very small, and oddly asymmetric. And then the Z axis went up a step, and printed this - or tried to:


That looks a bit thin but more like what I expected, albeit with a serious problem: most of those dots didn't have anything underneath them, and the printer was dutifully trying to print them in mid-air. That doesn't generally work. I killed the print, and set about figuring out how to fix it.

The simulated print pictures are from Repetier-host, which lets you step through a print layer by layer. The next two layers were loops and circles but I found a nice solid ring at layer five:


That's what I wanted to have for my first layer, but it was already a millimeter in the air.

Keeping in mind that this is a piece of sculpture rather than a machine part, I didn't have any qualms about modifying it a little to make it print better. I'm sure there are ways to slice off the bottom millimeter of the STL in Meshlab or Netfabb or some other program that I don't know how to use, but I was looking for something I knew, and it would be nice to avoid having to re-slice. Did I mention that the slicing process was slow? I actually left it running overnight, so I'm not sure how slow, but I really wanted to avoid reslicing. So I opened up the .gcode file in my favorite editor, vi, to see what I could do.

I should stop here and point out that there's no need to use vi for this task. Use anything that can edit a text file without adding formatting and font changes and paragraph styles; something that advertises itself as a "programmer's editor" or "text editor" will likely work. The biggest advantage of vi for this task is the ability to repeat a command a specified number of times, which comes in handy a little later.

The first few lines of the file are comments, laying out how Slic3r was configured. The next few are a kind of preamble, with calibration, temperature settings for the heated bed and hotend, etc. I was looking for the first lines that commanded the printer to move, using the G1 command:

G1 F1200.000 E-3.00000
G92 E0
G1 Z0.200 F7800.000
G1 X78.016 Y84.757 F7800.000
G1 E3.00000 F1200.000
G1 X78.736 Y84.197 E3.03034 F1200.000

The "G1 Z0.200" is key, that's where the printing actually begins. The first layer consists of everything between that line and the next move command for the Z axis:

G1 F1200.000 E0.04300
G92 E0
G1 Z0.400 F7800.000
G1 X89.870 Y115.575 F7800.000
G1 E3.00000 F1200.000

This print is using 0.2 mm layers, so every time a new layer starts the Z height jumps by that much. I can keep searching through the file for "G1 Z" and find the start of each layer; since I want the print to begin at layer five, I"ll look for when the height reaches 1 mm:

G1 F1200.000 E2.72067
G92 E0
G1 Z1.000 F7800.000
G1 X96.349 Y83.331 F7800.000
G1 X93.815 Y86.897 F7800.000

It happens to be line 4328. Jumping back to the beginning of the first layer, I note that it's on line 38, so I use vi's delete line command to get rid of 4289 lines between them. That gives me back-to-back Z moves, but I don't want the printer going up to 1 mm; I need it to stay at 0.2 mm and print the old fifth layer as the new first. So I have to fool it with another G-code command, one that Slic3r uses all the time for the extruder but never for the XYZ axes:

G1 Z0.200 F7800.000
G92 Z1.000 ; fool the printer into thinking that it's at 1 mm already
G1 Z1.000 F7800.000
G1 X96.349 Y83.331 F7800.000
G1 X93.815 Y86.897 F7800.000

This makes the second Z move command do nothing, but I've left it there as a place marker. Now I can upload the modified file, and watch as the print gets a nice, solid foundation.




For some reason the first layer is slightly different color, but that made it easier to photograph so I won't complain. I'm quite pleased with the finished product, too!


Incidentally, this trick of editing gcode can also be used to salvage a part that's gone bad, especially if it's mostly finished with just a little more to do, and the remainder is in one piece. You'll need a way to figure out which layer the printer was working on when it failed, probably by measuring the height of the partial print with your calipers. Then find the closest layer to that height by searching for Z moves, delete everything between the beginning of the first layer and that point, and use G92 to reset the Z height as above. With a little luck, and glue, you may save yourself a lot of frustration. . .

1 comment:

  1. Very nice! I used MeshLab awhile back to do the same thing, but then wasn't getting good adhesion. I have a heated bed now, so it might be time to try again...

    ReplyDelete