How to edit gcode? - Is it possible to salvage a job by restarting after a jammed extruder?

Hello! I was about 17 hours into a long, 100+ hour print of a Mandalorian helmet, and after about 31.5 mm of printing, during a time I was not directly monitoring, the filament jammed (seems there was a bur or flared off piece on the incoming feed strand), and I did not catch it until the unit had “air printed” nothing for about a half an inch or so!

Is it possible to try to salvage such a job by restarting with edited gcode after a jammed extruder has been cleared?

How would I edit the gcode to have it start at 31.5 mm, both in its placement and at the corresponding point in the build?

Am I barking up the wrong tree and should just consider the prior printing a waste?

I’ve done it! Air Print Recovery - A Success Story

Good luck!

Thank you! I will check that link out.

I’m finally attempting to do this, but currently using Cura.

I’m “replaying” the layer-by-layer printing process. Based on my calculations, the previous attempt printed well up through layer #134 (while my print settings were based on an initial layer height of 0.2 mm, and a layer height of 0.24 mm).

One step you mentioned in your write-up that I’m too new and too green to understand is how you discerned from that layer playback info, which line of gcode it was?

Quote: “The model was sliced using Simplify3D, but Cura has similar features to what I’m about to describe. Measured the height of printed perimeter with a micrometer, and found the corresponding layer in S3D.Then I located the exact line it was printing (at least within a few mm) by replaying that layer in the preview, line by line. The exact line was 93,066, as reported by S3D.”

Does Cura have a similar “as reported by” feature? If so, how do I access it?

Thanks for any advice.

OK, good news, the gcode actually has layer numbers in its remarks. The original gcode was rendered from Snapmaker’s Luban, so I guess that’s a built in thing. Now I’m stressing over how to follow the rest of your steps.

If someone should know… does the gcode (from Luban) mention of layer number refer to what just completed? Or to what is about to be started? Here’s an example of the remarks giving layer number:

;TIME_ELAPSED:51527.428608
;LAYER:133
G0 X71.858 Y97.167 Z32.12

Have a look at the first and last time that comment exists and you’ll know the answer :wink:

Let us know too!

I had already searched for all instances, and there is only once instance. I don’t yet know enough about gcode to discern up from down. I’m currently watching YouTube tutorials on Marlin gcode to try to get my bearings!

Here’s the passage in focus, starting with line #876808, and going through line #876850:

0 X60.408 Y181.338
G0 X59.952 Y176.751
G0 X59.75 Y172.075
G0 X59.801 Y167.338
G0 X60.107 Y162.563
G0 X60.662 Y157.784
G0 X61.474 Y153.021
G0 X62.538 Y148.31
G0 X63.284 Y145.683
G0 X72.803 Y113.249
G0 X71.76 Y112.514
G0 X71.858 Y97.167
;TIME_ELAPSED:51527.428608
;LAYER:133
G0 X71.858 Y97.167 Z32.12
;TYPE:SUPPORT
G1 F3600 E4233.57092
G92 E0
G1 X71.887 Y97.173 E0.00118
G1 X72.133 Y97.987 E0.03512
G1 X72.903 Y99.307 E0.09611
G1 X75.026 Y100.65 E0.19638
G1 X73.49 Y103.123 E0.31257
G1 X73.543 Y103.655 E0.33391
G1 X75.468 Y105.704 E0.44612
G1 X73.121 Y107.95 E0.57577
G1 X72.865 Y107.821 E0.58722
G1 X72.338 Y107.928 E0.60868
G1 X71.416 Y109.013 E0.66551
G1 X69.399 Y106.959 E0.7804
G1 X70.663 Y105.124 E0.86934
G1 X70.547 Y104.567 E0.89204
G1 X67.843 Y102.879 E1.01927
G1 X66.639 Y102.247 E1.07354
G1 X66.839 Y102.059 E1.0845
G1 X67.59 Y101.451 E1.12306
G1 X68.511 Y100.851 E1.16693
G1 X69.756 Y100.293 E1.22139
G1 X70.343 Y99.118 E1.27381
G1 X70.474 Y98.898 E1.28403
G1 X71.181 Y97.883 E1.3334
G1 X71.858 Y97.167 E1.37273
G0 F4800 X69.342 Y100.873
G1 F3600 X68.68 Y101.17 E1.40169
G1 X67.799 Y101.744 E1.44366
G1 X67.271 Y102.172 E1.47078
G1 X68.023 Y102.566 E1.50467
G1 X69.342 Y103.389 E1.56672
G1 X69.342 Y100.873 E1.66714
G1 X70.021 Y100.569 E1.69683
G1 X70.661 Y99.287 E1.75402
G1 X70.783 Y99.082 E1.76354
G1 X71.46 Y98.111 E1.81078

So, GCODE is executed in sequence. If as you say there is a layer comment for every layer, you’ll be able to search for ‘;LAYER:’ in your file.

If the code between the first and second occurrence looks like a layer but the code before the first occurrence doesn’t, the comment precedes the layer.

If however the code between the first and second occurrence looks like a layer and the code directly before the first occurrence also looks like a layer, then the comment is after the layer.

Similarly look at the last two occurrences and make your conclusions.

I’m guessing that the actual sequence is comment, then layer, but I don’t have a GCODE file in front of me to confirm that.

I’m pondering on what you wrote and realizing you were probably meaning all mentions of layer, not just that one. However, since I don’t yet know what the in between content for a layer would look like, I’m still a ways from being able to discern what is up there. Still working on learning gcode. More son.

Are you searching for 133 also?

Yes, because I misunderstood your answer as thinking you meant there would be a before and after mention of the same number.

S3D has a display like this, that I was using to see exactly where the nozzle was:
image

It looks like Cura maybe doesn’t have the exact line number displayed in the previews. You could put the code excerpt between layer 133 and 134 (or the entire file, will just take longer to load) into ncviewer.com and play the file line by line to find the equivalent line number by looking at the nozzle position.

Below is the code from the start of the file down past the first mention of a “Layer #” (Layer 0), and so based on my totally uneducated guess, it looks like the layer remark comes before a layer, not after.

;Header Start

;FLAVOR:Marlin
;TIME:6666
;Filament used: 0m
;Layer height: 0.24

;header_type: 3dp
;thumbnail: data:image/png;base64, … [remainder of line snipped out for simpler pasting]
;file_total_lines: 6551863
;estimated_time(s): 410868.23000000004
;nozzle_temperature(°C): 205
;build_plate_temperature(°C): 70
;work_speed(mm/minute): 3600
;max_x(mm): 0
;max_y(mm): 0
;max_z(mm): 0
;min_x(mm): 0
;min_y(mm): 0
;min_z(mm): 0

;Header End

; G-code for 3dp engraving
; Generated by Snapmaker Luban 3.10.2
; Wed Dec 02 2020 3:49:30

M82 ;absolute extrusion mode
;Start GCode begin
M104 S205
M140 S70
G28 ;home
G90 ;absolute positioning
G1 X-10 Y-10 F3000
G1 Z0 F1800
M109 S205;Wait for Hotend Temperature
M190 S70;Wait for Bed Temperature
G92 E0
G1 E20 F200
G92 E0
;Start GCode end
G92 E0
G1 F3600 E-5
;LAYER_COUNT:1062
;LAYER:0
M107
G0 F1440 X69.894 Y94.389 Z0.2
;TYPE:SKIRT
G1 F3600 E0
G1 F1080 X70.324 Y94.124 E0.0168

Cool tip! Thank you again!!

1 Like

I didn’t realise this prior, but it looks like viewing line numbers in the Cura previews is actually impossible based on how Cura currently renders previews:

Thanks. Yes, I had read that very feature request thread earlier today!

I was a bit baffled by the bolded sentences in this paragraph, but then I read more on the Extruder “virtual axis” and I think I follow it now!

Copied the gcode file and modified it. First, went to the last good printed line, 93,066 and looked up the file. Found the previous G92 E0 command, and changed it to what the previous extrusion was on line 93,065, which was E115.7035, and deleted all of the gcode in between, so when the print starts it won’t extrude 115mm of filament.

1 Like

So, in my planned deletion, I am not deleting the commands from layer 1 that turned the fan on and lowered the bed temp from 70 to 50 degrees. And if I use the start of layer 133 as the beginning of what all else I am leaving in, it seems to set extruder axis at E4233.57092 with its own “G92 E0” command soon after (see below). It also sets the Z at 32.12 mm. Does it sound like I’m on the right track?

;LAYER:133
G0 X71.858 Y97.167 Z32.12
;TYPE:SUPPORT
G1 F3600 E4233.57092
G92 E0

1 Like

Below is how the proposed new file would look, after my deletions, from the start of the file, through the beginning of layer 133, which is my best guess for where I need to restart the job.

This is nerve wracking for a newbie like me! LOL. Please let me know if anyone sees something glaring that I’m overlooking! I have something like 15-17 hours worth of print product I’m hoping to salvage.

;Header Start

;FLAVOR:Marlin
;TIME:6666
;Filament used: 0m
;Layer height: 0.24

;header_type: 3dp
;thumbnail: data:image/png;base64, [SNIP]
;file_total_lines: 6551863
;estimated_time(s): 410868.23000000004
;nozzle_temperature(°C): 205
;build_plate_temperature(°C): 70
;work_speed(mm/minute): 3600
;max_x(mm): 0
;max_y(mm): 0
;max_z(mm): 0
;min_x(mm): 0
;min_y(mm): 0
;min_z(mm): 0

;Header End

; G-code for 3dp engraving
; Generated by Snapmaker Luban 3.10.2
; Wed Dec 02 2020 3:49:30

M82 ;absolute extrusion mode
;Start GCode begin
M104 S205
M140 S70
G28 ;home
G90 ;absolute positioning
G1 X-10 Y-10 F3000
G1 Z0 F1800
M109 S205;Wait for Hotend Temperature
M190 S70;Wait for Bed Temperature
G92 E0
G1 E20 F200
G92 E0
;Start GCode end
G92 E0
G1 F3600 E-5
;LAYER_COUNT:928 (which is 1062 - minus layers 0-133, a total of 134 layers)
;LAYER:0 – DELETED except for fan off command.
M107 ;fan off command

;LAYER:1
M140 S50 ;heat the bed to 50 degrees Celsius
M106 S255 ;fan on full, 100%

;LAYER:133
G0 Z32.12
G0 X71.858 Y97.167
;TYPE:SUPPORT
G1 F3600 E4233.57092
G92 E0
G1 X71.887 Y97.173 E0.00118
G1 X72.133 Y97.987 E0.03512
G1 X72.903 Y99.307 E0.09611
G1 X75.026 Y100.65 E0.19638
G1 X73.49 Y103.123 E0.31257
G1 X73.543 Y103.655 E0.33391
G1 X75.468 Y105.704 E0.44612

1 Like