<p>Your print end code should have read something akin to this:</p>

<pre><code>; Filament sy end gcode
G4 ; wait
M221 S100
M106 S0 ; turn off cooling fan
M104 S0 ; turn off extruder
M140 S0 ; turn off bed

; End code
G1 F1800 E-3 ; retract 3 mm
G1 Z30 ; Move print head up 30mm
G28 X0 ; home x and y axis
M84 ; disable motors
M300 S2600 P100; Beep
</code></pre>

<p>The problem with your end code is the <code>G90</code> for <strong>absolute</strong> measurements together with the formula <code>G1 Z{z_offset+min(layer_z+30, max_print_height)}{endif}</code> to set the height. The printer itself doesn't calculate anything. That what it doesn't interpret, it ignores, interpreting that whole thing as something crazy like <code>G1 Z30</code> to force the printer to go to Absolute 30 mm above absolute 0. To fix it,  your slicer would need to calculate <code>{z_offset+min(layer_z+30, max_print_height)}</code> for the printer - which seems to come out to 30mm above the print and then an if-statement that is not started anywhere.</p>

<p>Going up 30 mm can be much easier be done by staying in <code>G91 ; relative measurements</code> and calling <code>G1 Z30</code> to go up another 30 mm, though this might be too high for the printer frame.</p>

CC BY-SA 4.0
2019-02-03T03:48:48.117Z
The G-code in the slic3r reads:
G90
{if layer_z < max_print_height}G1 Z{z_offset+min(layer_z+30, max_print_height)}{endif} ; Move print head up

I notice that 'if' statement doesn't seem to be present in the output G-code file. Is this the problem?
Jonathan Gallant-Mills
CC BY-SA 4.0
2019-02-03T05:00:18.410Z
@JonathanGallant-Mills yes, it is a problem. you should also have some else... or just skip that
Trish
CC BY-SA 4.0
2019-02-02T22:23:08.473Z
2019-02-02T22:33:02.077Z
2019-02-02T22:33:02.077Z
Trish
<p>The same thing happened to me several years ago. My print was a fairly tall part for my delta printer, about 220 mm. In many previous prints, the print head would always go up after finishing, but what I didn't know was that the Slic3r finish print routine specified an absolute Z height of about 200 mm. When the tall part finished, the still-hot print head moved down and ruined the top of the print. </p>

<p>After figuring out that the routine had an absolute reference, I replaced it with a relative movement 20 mm up. It's worked fine since then. An easy fix.</p>

CC BY-SA 4.0
2019-10-25T18:54:01.410Z
2019-10-25T18:54:01.410Z
PikesPeakCode
<p>You are using <strong>incorrect commands</strong> in your end-code for the <strong>incorrect tool</strong> with respect to the print head raise.</p>

<p>Slic3r has no knowledge of the maximum printer height (as in variable <code>max_print_height</code>) because there is <strong>no input field to specify this</strong>, as can be seen in this partial screenshot:</p>

<p><a href="https://i.sstatic.net/qPz1z.png" rel="noreferrer"><img src="https://i.sstatic.net/qPz1z.png" alt="Slic3r print area settings"></a></p>

<p>However, in Slic3r PE (Prusa Edition), there is a possibility to enter such a value, as seen in the following partial screenshot:</p>

<p><a href="https://i.sstatic.net/lCHxV.png" rel="noreferrer"><img src="https://i.sstatic.net/lCHxV.png" alt="Slic3r PE print volume settings"></a></p>

<p>Note that in both editions, the <code>Bed shape</code> interface is equivalent when <code>Set...</code> is pressed:
<a href="https://i.sstatic.net/jTLBm.png" rel="noreferrer"><img src="https://i.sstatic.net/jTLBm.png" alt="Slic3r and Slic3r PE bed area settings"></a></p>

<p>To use the raising of the head, respecting the maximum print height, in <strong>Slic3r PE</strong>, you need to add the following line:</p>

<pre><code>{if layer_z &lt; max_print_height}G1 Z{z_offset+min(layer_z+60, max_print_height)}{endif}
</code></pre>

<p>This will parse fine in <strong>Slic3r PE</strong>, but not in <strong>Slic3r</strong> (as <code>max_print_height</code> is not known).</p>

<p>If you want such a command in <strong>Slic3r</strong>, you need to enter (for a printer with a maximum print height of 240&nbsp;mm):</p>

<pre><code>G1 Z{[z_offset]+min([layer_z]+3, 240)}
</code></pre>

<p>results in Slic3r for a 20x20x20&nbsp;mm calibration cube with a zero <code>z_offset</code> to:</p>

<pre><code>G1 Z23
</code></pre>

CC BY-SA 4.0
2019-02-04T20:27:30.483Z
But there shouldn't be a need to change the Z-pos at all!  Once the print is done, the head should be able to clear the last layer applied and move to X=0,Y=0 . No need to do anything else, right?
Carl Witthoft
CC BY-SA 4.0
2019-02-04T20:46:21.953Z
@CarlWitthoft Have you never seen the straight ironing line that some slicers generate over the top layer? Raising the head prevents that.
0scar
CC BY-SA 4.0
2019-02-05T13:21:00.713Z
@Oscar  I have to admit I have not.  Certainly a good reason, then, to do a small relative-Z move first.
Carl Witthoft
CC BY-SA 4.0
2019-02-03T15:19:17.930Z
2019-02-03T18:35:10.463Z
2019-02-03T18:35:10.463Z
0scar
<p>I just completed my first print on my Ender-3 and when the print finalized itself the nozzle didn't elevate itself to clear away from the piece. I watched as the nozzle slowly lowered itself into my print and destroy it. Here is the gcode generated by Slic3r used:</p>

<pre>
; Filament-specific end gcode
G4 ; wait
M221 S100
M106 S0 ; turn off cooling fan
M104 S0 ; turn off extruder
M140 S0 ; turn off bed
G91
G1 F1800 E-3
G90
G1 Z{z_offset+min(layer_z+30, max_print_height)}{endif} ; Move print head up
G28 X0 ; home x and y axis
G1 Y180; Remove Print Position
M84 ; disable motors
M300 S2600 P100; Beep
; filament used = 24040.5mm (57.8cm3)
; total filament cost = 0.0
</pre>

<p><a href="https://i.sstatic.net/mZncw.jpg" rel="noreferrer"><img src="https://i.sstatic.net/mZncw.jpg" alt="preview of the destruction"></a></p>

<g-code><creality-ender-3>
Why did my printer's nozzle dig itself into my print?
Jonathan Gallant-Mills
# Why did my printer's nozzle dig itself into my print?

(Asked by: username_0 on 2019-02-02)

I just completed my first print on my Ender-3 and when the print finalized itself the nozzle didn't elevate itself to clear away from the piece. I watched as the nozzle slowly lowered itself into my print and destroy it. Here is the gcode generated by Slic3r used:

```

; Filament-specific end gcode
G4 ; wait
M221 S100
M106 S0 ; turn off cooling fan
M104 S0 ; turn off extruder
M140 S0 ; turn off bed
G91
G1 F1800 E-3
G90
G1 Z{z_offset+min(layer_z+30, max_print_height)}{endif} ; Move print head up
G28 X0 ; home x and y axis
G1 Y180; Remove Print Position
M84 ; disable motors
M300 S2600 P100; Beep
; filament used = 24040.5mm (57.8cm3)
; total filament cost = 0.0

```

[![preview of the destruction](https://i.sstatic.net/mZncw.jpg)](https://i.sstatic.net/mZncw.jpg)

**Tags:** g-code, creality-ender-3


---

## 3 answers

### Answer by username_3 on 2019-02-03. Score: 5 | Accepted answer

You are using **incorrect commands** in your end-code for the **incorrect tool** with respect to the print head raise.

Slic3r has no knowledge of the maximum printer height (as in variable `max_print_height`) because there is **no input field to specify this**, as can be seen in this partial screenshot:

[![Slic3r print area settings](https://i.sstatic.net/qPz1z.png)](https://i.sstatic.net/qPz1z.png)

However, in Slic3r PE (Prusa Edition), there is a possibility to enter such a value, as seen in the following partial screenshot:

[![Slic3r PE print volume settings](https://i.sstatic.net/lCHxV.png)](https://i.sstatic.net/lCHxV.png)

Note that in both editions, the `Bed shape` interface is equivalent when `Set...` is pressed:
[![Slic3r and Slic3r PE bed area settings](https://i.sstatic.net/jTLBm.png)](https://i.sstatic.net/jTLBm.png)

To use the raising of the head, respecting the maximum print height, in **Slic3r PE**, you need to add the following line:

```
{if layer_z < max_print_height}G1 Z{z_offset+min(layer_z+60, max_print_height)}{endif}

```

This will parse fine in **Slic3r PE**, but not in **Slic3r** (as `max_print_height` is not known).

If you want such a command in **Slic3r**, you need to enter (for a printer with a maximum print height of 240 mm):

```
G1 Z{[z_offset]+min([layer_z]+3, 240)}

```

results in Slic3r for a 20x20x20 mm calibration cube with a zero `z_offset` to:

```
G1 Z23

```

> **Comments:**
> **username_4**: But there shouldn't be a need to change the Z-pos at all!  Once the print is done, the head should be able to clear the last layer applied and move to X=0,Y=0 . No need to do anything else, right?  
> **username_3**: @username_4 Have you never seen the straight ironing line that some slicers generate over the top layer? Raising the head prevents that.  
> **username_4**: @Oscar  I have to admit I have not.  Certainly a good reason, then, to do a small relative-Z move first.  

---

### Answer by username_1 on 2019-02-02. Score: 1

Your print end code should have read something akin to this:

```
; Filament sy end gcode
G4 ; wait
M221 S100
M106 S0 ; turn off cooling fan
M104 S0 ; turn off extruder
M140 S0 ; turn off bed

; End code
G1 F1800 E-3 ; retract 3 mm
G1 Z30 ; Move print head up 30mm
G28 X0 ; home x and y axis
M84 ; disable motors
M300 S2600 P100; Beep

```

The problem with your end code is the `G90` for **absolute** measurements together with the formula `G1 Z{z_offset+min(layer_z+30, max_print_height)}{endif}` to set the height. The printer itself doesn't calculate anything. That what it doesn't interpret, it ignores, interpreting that whole thing as something crazy like `G1 Z30` to force the printer to go to Absolute 30 mm above absolute 0. To fix it, your slicer would need to calculate `{z_offset+min(layer_z+30, max_print_height)}` for the printer - which seems to come out to 30mm above the print and then an if-statement that is not started anywhere.

Going up 30 mm can be much easier be done by staying in `G91 ; relative measurements` and calling `G1 Z30` to go up another 30 mm, though this might be too high for the printer frame.

> **Comments:**
> **username_0**: The G-code in the slic3r reads: G90 {if layer_z < max_print_height}G1 Z{z_offset+min(layer_z+30, max_print_height)}{endif} ; Move print head up  I notice that 'if' statement doesn't seem to be present in the output G-code file. Is this the problem?  
> **username_1**: @username_0 yes, it is a problem. you should also have some else... or just skip that  

---

### Answer by username_2 on 2019-10-25. Score: 1

The same thing happened to me several years ago. My print was a fairly tall part for my delta printer, about 220 mm. In many previous prints, the print head would always go up after finishing, but what I didn't know was that the Slic3r finish print routine specified an absolute Z height of about 200 mm. When the tall part finished, the still-hot print head moved down and ruined the top of the print.

After figuring out that the routine had an absolute reference, I replaced it with a relative movement 20 mm up. It's worked fine since then. An easy fix.


---

