I have an Ender 3 that I use from time to time – I’m afraid my excursions into 3D CAD have been fairly primitive so far, so in the last week, when I wanted to modify a Thingiverse design for a router base I decided to have a go at editing the G-Code rather than re-drawing the part in 3D CAD. Partly sheer laziness on my part, but partly the realisation that as the part had a long section of M54 X 4mm thread (!), it might take a while to get the design “just right” in CAD, and at ~ 5 hours of printing per part that could end up being very time consuming.
Anyhow, there ensued an interesting excursion into the mysteries of 3D printer G-code. Easy enough to pick out, and delete, the chunk of code representing the material I didn’t want – the part printed vertically, and I just had to pick out the Z moves for the section I wanted to remove, and edit the Z values of the subsequent moves to adjust for the removed material. The section removed was 33mm long, starting from 25.04mm above the build plate, so all Z values in moves from 58mm onwards needed reducing by 33mm. So far, so good. Saved the file, started up the printer. All was well until it reached the 25mm level, and then the printer ejected the filament from the extruder, and carried on doing “air moves” for the rest of the program – at least, until I killed the run.
Much head scratching etc., until a bit of research on ‘t web revealed the non-obvious (to me at least!) fact that the extruder feed is controlled by the same G1 commands that control the printer moves – the parameters X,Y,Z define the end position, F defines feedrate, E defines the length of filament that will be extruded during the move. Unfortunately, and very counter-intuitively, the E value is either absolute or relative, depending on whether you are using absolute or relative coordinates, and Cura seems to choose to use absolute coordinates (selected with M82). This means that the E value is the absolute length extruded since E was last zeroed (using a G92 command); the amount extruded in any one move will be the value of E in that command less the value of E in the previous command. Thankfully, in my case, somewhere in the chopped out section of code there was a G92 E0 command that reset the extruder, and the E value in the first command after the cut was less than the last value before, so the machine unloaded the filament – if it had been the other way around, the machine would have attempted to extrude a very large amount of filament during the first move after the cut, which would have been “interesting”.
Inserting a G92 EXXX after the cut to reset the extruder to XXX, the value of E in the last move of the deleted section, restored proper operation and the part then printed as I had intended.
It did leave a question in my mind as to why the slicer chooses to operate in absolute coordinates – seems to me that life would be a lot simpler for the average hacker if the file was specified in relative moves. Anyone know why they do this? Obviously, for the most part, it doesn’t matter, only when you need to go into the code and “fix” stuff.