3
$\begingroup$

SUMMARY: I use a Creality Ender 3 and Cura 4.8 slicer. I need to print multiple objects 'one-at-a-time' (Cura allows this, that is fine) and I must specify the order in which each model is printed but Cura does not have this facility. My question is: how can I change the order of the printed objects by editing the G-code?

DETAIL: Sometimes it is essential or useful to specify the order of printing multiple objects in a 'one-at-a-time' batch print to allow the printing of some objects that are taller than the X-gantry clearance together with other objects that are shorter than the gantry because if you can control the order then you can print the small objects first and then the tall objects (because the gantry won't get in the way of the already-printed small objects but if the tall objects are printed first then the gantry will crash into them). Specifically I am talking about two or more objects printed at roughly the same Y-level on the print bed (I know you can 'get-away' with it if you separate them in Y but I want to print multiple rows of such objects). Without control over print order this cannot be done thereby limiting productivity (number of models per print run).

WHAT HAVE I DONE TO RESOLVE THIS ALREADY: I can control the print order of multiple identical objects in Cura (they are printed in reverse order to their creation as duplicates of an initial model and if there are problems you can sometimes control the order by moving objects around) but this does not work for multiple different objects. I did several Google searches and found some conversations that deal with this issue including on the official GitHub page of the Cura slicer (see for example this Cura GitHub Discussion). The conclusion given by the Cura developers is that they understand the limitation, but it is not an issue for Ultimaker printers so they have no plans to make user-customisable print order a feature in Cura because it would be too much work for them to do the changes and maintain them. One person mentioned a python script to allow post editing of G-code to change print order but I could find no links to it. Another person described a 'workaround' in Cura to do with grouping and ungrouping models in a specific sequence but this does not work for me (?maybe it only worked in older versions of Cura). Perhaps someone on this forum has G-coding knowledge and could shed some light on how it may be done? [PS: I am only interested in G-code editing solutions for this question, or a Cura workaround that works in v4.8 - I don't use Octoprint/Rasperry Pi controllers].

Thanks.

[EDIT] Thanks to the contributors in the accepted answer I managed to do this with 'cut-and-paste' (via a small C program - you could do it manually but it is tedious and there is more risk of making a mistake if you have many models). I used the comments in Cura's G-code and a few other G-code cues to calculate the correct splice points.

It works provided you take care to ensure the new extruder code is either altered according to the new model positions or use the 'relative extrusion' mode when saving the original G-code from Cura (I used the latter method). Also you must splice the G-code at the right points to ensure pre-model start and post-model finish G-code commands are properly carried around and the final model in the original G-code needs a terminal G0 command to be constructed if it is no longer terminal in the new order so that it can properly position the nozzle to go to the next model in the chain. Also you need to ensure M107 is included prior to each model's first layer. There is danger in doing any of this - the new G-code might damage your printer if you get anything wrong - but it can work (at least it has for me).

I made several manual checks on the new re-arranged G-code as well as loading it into Cura and running Cura's nozzle simulator on it to ensure it does what I expected of it prior to risking running it in my printer, but after that it printed OK.

$\endgroup$
3
  • $\begingroup$ This would suggest a useful feature request to forward to the Cura development team, assuming it isn't already in 4.9... $\endgroup$
    – Zeiss Ikon
    May 25 at 16:42
  • 1
    $\begingroup$ @ZeissIkon The Cura developers know that people want this feature but they don't want to do it. It is potentially dangerous but then messing about with Cura settings (overriding machine defaults for your printer, etc.) is similarly dangerous. As long as people know that and accept the risk then that's fine I think. If there is enough demand then perhaps if I can get my code into a form others can easily use I will post it on GitHub - with a big health warning! $\endgroup$
    – WildCat
    May 25 at 17:01
  • $\begingroup$ Seems obvious that you'd want/need to make the shorter parts first, even if they're spread to the corners of the bed. If they're spread enough, on the other hand, it doesn't matter as long as none of them are high enough to interfere with the gantry and they're far enough apart not to hit the hot end fan cases etc. $\endgroup$
    – Zeiss Ikon
    May 25 at 17:33
3
$\begingroup$

You can open the G-code file in any text editor and copy-paste the relevant sections of G-code to reorder them. It will be fairly obvious where one object ends and the next one starts because the printhead will move back down to Z=0; you can do a simple search to find the commands that move to Z=0 (in my version of Cura, it inserts a comment ;LAYER:0 at the start of each object).

To ensure that the extruder starts in the correct position, look back at the previous print (in the original order) to see where the extruder finished, then insert (at the start of the new print) G92 Exx.xx where xx.xx is the previous position of the extruder. If looking back to the previous print is too tedious, you can also just use the very first extruder position in the print itself and use that. It will just skip printing the very first section of brim/skirt, which doesn't make a big difference.

$\endgroup$
8
  • $\begingroup$ Unfortunately it is not that simple. The position of the extruder progresses from model to model in the original print order - and it is cumulative. So the first model E starts at 0. The second model E starts at (let's say) 23.214 mm because that's how much filament has been extruded so far for your first model. If you just swap them around with cut and paste then the printer will spew forth 23.214 mm of filament before starting your first print then, when it gets to the second one it will retract back to E=0 sucking up air all the way and your second print will be made of thin air. $\endgroup$
    – WildCat
    May 22 at 11:24
  • 1
    $\begingroup$ @WildCat Good point. You can just use G92 to fix that. $\endgroup$ May 22 at 11:38
  • 3
    $\begingroup$ @WildCat The G92 command really does fix that issue. You don't need to (programatically) change all of the E position commands. Using G92 tells the printer that it should "virtually" move the extruder, that is, not physically move it but only update the printer's memory to set the extruder to that position. For example (if the starting position is zero) issuing G92 E10 followed by G1 E20 results in 10mm of filament being extruded, the same as if we had just issued G1 E10. $\endgroup$ May 22 at 12:30
  • 1
    $\begingroup$ Switching slicer to relative extrusion mode might be an easier option. $\endgroup$ May 22 at 14:10
  • 1
    $\begingroup$ @WildCat: It's a matter of cumulative floating point inaccuracy in letting the printer's firmware sum up the the decimal values printed in the g-code, which are each individually inexact, vs getting a new position value from the slicer that gets rounded to the nearest representable value on each move. This is a real mathematical issue, but the order of magnitude of the error is likely much smaller than the error on calibration of your e-steps or filament diameter, so in practice I think it's a non-issue. $\endgroup$ May 23 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.