<p>This is my code:</p>

<p>START CODE:</p>

<pre><code>M117 Preparing....    ; Nozzle clean message

M140 S{material_bed_temperature_layer_0}   ; set bed temp

M107                  ; Turn layer fan off
G21                   ; Metric
G28                   ; Home X/Y/Z axis
G0 X0 Y0 Z20 F9000    ; Move up 20mm for heating

M104 S{material_print_temperature_layer_0} ; set extruder temp
M190 S{material_bed_temperature_layer_0}   ; wait for bed temp
M109 S{material_print_temperature_layer_0} ; wait for extruder temp

G92 E0                ; Zero extruder

G28                   ; Home X/Y/Z axis
G0 X1 Z0.1 F9000      ; Move up 0.1mm
G0 Y10 F500           ; Move 10mm to get rid of material
G0 Z1 F9000           ; Move up
G0 Y110 F9000         ; Move to line start
G0 Z0.2 F9000         ; Move down

G1 Y20 E25 F500       ; Extrude 25mm filament over 90mm Y axis
G1 Y10 F500           ; Move 10mm without extracting
G92 E0                ; Reset extruder
G1 E-7 F1400          ; Retract 7mm filament

M117 Printing....     ; Printing message
</code></pre>

<p>END CODE:</p>

<pre><code>G91                   ; Incremental coordinates
G1 E-3 F1800          ; Retract
G1 Z10 F9000          ; Move up
G90                   ; Absolute cooridinates
M106 S0               ; Turn off cooling fan
M104 S0               ; Turn off extruder
M140 S0               ; Turn off bed
G1 X0 Y220 F9000      ; Move back
M84                   ; Disable motors
M117 Finished!.       ; Printing message
</code></pre>

<p>It's almost working perfectly. I can start prints without checking if the first layer is good (requires a leveled bed).</p>

<p>I am open for improvements</p>

CC BY-SA 4.0
2020-02-13T03:38:10.227Z
This works well, only thing I would note is that in Slic3R I had to swap the curly braces for square brackets.
Mark Carpenter Jr
CC BY-SA 4.0
2021-08-02T13:17:51.297Z
How does retracting work? Doesn't it mean that 7mm needs now to be extracted (pushed) again before it starts flowing from the nozzle?
IttayD
CC BY-SA 4.0
2018-11-24T10:39:45.060Z
2018-11-24T14:00:02.517Z
2018-11-24T14:00:02.517Z
Benni Zwölfer
<h2>Blob &amp; Cut</h2>
<p>A different approach is to move to a position out off the print bed, then extrude a long piece of filament and then move forward, cutting the filament at the edge of the print surface. A sample G-code that needs to be adjusted to your bed:</p>
<pre><code>G28
G1 Y-5 X5 Z0.1 F500    ; Move off the print surface, a bit above the 0
G92 E0                 ; reset extrusion distance
G1 F200 E10            ; extrude 10mm of feed stock
G92 E0                 ; reset extrusion distance
G1 Y2 F500             ; Move into the print platform
</code></pre>

CC BY-SA 4.0
2018-07-15T15:14:45.077Z
2018-07-15T15:14:45.077Z
2020-06-18T08:29:41.667Z
Trish
<p>I've experimented a lot with priming/swiping in the G-code prologue, as a result of realizing from <a href="https://3dprinting.stackexchange.com/a/8643/11157">this question and answer</a> how important it is to get it right. The key points are:</p>

<ul>
<li>Don't go back and forth; you risk picking back up material you already got rid of. Just swipe in one direction.</li>
<li>Don't overextrude. This can lead to ending with pressure remaining (especially for printers with bowden extruders) after the swipe/prime line is finished. It's fine if your extrusion rate is so low that adhesion doesn't start til halfway down the line.</li>
<li>Slow movement with fan on is good.</li>
</ul>

<p>And with that said, here's what I use with my Ender 3:</p>

<pre><code>M106 ; Max fan to discourage ooze sticking to nozzle
G28 ; Home all axes
G92 E0 ; Reset Extruder
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching
G1 X0.1 Y20 Z0.3 F5000.0 ; Move to start position
G1 X0.1 Y200.0 Z0.3 F750.0 E18 ; Draw priming line
G92 E0 ; Reset Extruder
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching
</code></pre>

<p>I also undo all but 1mm of the filament retraction at the end of my epilogue (custom end) G-code, to leave the printer in a state comparable to having freshly loaded filament. If you don't undo the retraction here, the low extrusion rate in the prologue might not be enough to prime the next time you print, but increasing it would over-prime in the case where you're dealing with freshly loaded filament.</p>

CC BY-SA 4.0
2019-08-15T23:10:27.213Z
2019-08-16T05:56:07.657Z
2019-08-16T05:56:07.657Z
R.. GitHub STOP HELPING ICE
<h2>What code we have so far</h2>
<p>The code already made by Ultimaker Cura 3 (and then commented on) can be explained a little more:</p>
<p><code>G28 ;Home</code><br>
<em>This homes your machine to hit end stop positions, from now on your printer knows the coordinates of the print volume. This place it knows as &lt;0-0-0&gt; - check where that is: above the print surface or next to it!<br></em>
<code>G1 Z15.0 F6000 ;Move the Gantry up 15mm going fast</code><br>
<em>Instruct the build plate to move down, or in your case lift the head up 15 mm at 6000 mm/min<br></em>
<code>;Prime the extruder</code><br>
<em>This is a comment that the nex code will deal with priming the nozzle<br></em>
<code>G92 E0 ; reset extrusion distance</code><br>
<em><a href="https://reprap.org/wiki/G-code#G92:_Set_Position" rel="nofollow noreferrer">G92</a> sets the position of the extruder by resetting the current position to the specified value of zero<br></em>
<code>G1 F200 E3 ; extrude 3mm of feed stock</code><br>
<em>This will extrude 3 mm of filament at a feedrate of 200 mm/min<br></em>
<code>G92 E0 ; reset extrusion distance</code><br>
<em>This will reset the extruder length again to zero<br></em></p>
<h2>Result of the code</h2>
<p>Basically you will have some filament dangling on your nozzle now, or falling of as the nozzle is hot creating a fine string. You now are facing the possibility that the primed material will be dragged along the build plate to the start of the print.</p>
<h2>Nozzle Preparation: Priming sequences</h2>
<h3>Ultimaker 3: 'blob'&amp;swipe</h3>
<p>An alternative I really like is the priming sequence of the Ultimaker 3. The hot end is instructed near the origin of the printer at about a height of 2 mm above the build plate when it starts to extrude plastic, once the extruded plastic becomes a puddle of about 6 mm in diameter the build plate lowers a few mm's and keep extruding for a bit. It then moves in positive Y direction (to the back) and raises the platform (this is the swipe action), then retracts and starts to move to the print start. Now the puddle of filament stays near the origin and will not be dragged.</p>
<p>You can easily make a similar schematic for your printer, I've done so also for various printers. Try and experiment what works best for you. The swipe action is the movement where the nozzle will be instructed to move near the build plate while moving in a certain direction (Y or X), a height of a few tenths is enough to swipe.</p>
<p>I don't have my exact profile here, but you could add (skipping feedrates):</p>
<pre><code>G1 Y15 Z0.2 ; moves the nozzle backwards and down from 15 mm to 0.2 mm
G1 Y20 Z0.2 ; swipes the nozzle, this should cut off the &quot;worm&quot;
G1 Z1     ; raise for movement to start of print to add a little space to travel
</code></pre>

CC BY-SA 4.0
2018-07-10T10:15:32.970Z
2019-11-06T13:37:39.547Z
2020-06-18T08:29:41.667Z
0scar
<h2>The lazy way: Skirt/Brim</h2>
<p>With my TronXY X1 I learned pretty fast, that this first bit of extrusion on an unheated bed can totally mess up the first layer by being just in the way, as explained in the question.</p>
<p>To some degree, this behavior can be avoided by adding a skirt of a certain length. An equally good alternative that also increases bed adhesion for tricky parts is the brim. Both are not set via G-code but can be added by the slicer. In Ultimaker Cura both are found in the tab Build Plate Adhesion as type, as the following pictures show:</p>
<h3>Skirt: 2 lines, minimum length 250mm</h3>
<p><a href="https://i.sstatic.net/iN6IM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iN6IM.png" alt="Skirt: 2 lines, minimum length 250mm" /></a></p>
<h3>Brim: minimum length 250mm, 8mm width</h3>
<p><a href="https://i.sstatic.net/uL1Fn.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/uL1Fn.png" alt="Brim: minimum length 250mm, 8mm width" /></a></p>
<h2>The Prusa Priming-line</h2>
<p>Angus/MakersMuse introduced me to the Prusa Priming Line in one of his <a href="https://www.youtube.com/watch?v=6csbJ5965Bk" rel="nofollow noreferrer">tutorial videos</a>. For his Wanhao he used (for the video) just this start G-code script:</p>
<pre><code>G28
G1 Y-3 F500 ; Move out of print volume
G1 X60 E9 F500 ; start purge line
G1 X100 E12.5 F500 ; finish purge line
</code></pre>
<p>This resulted in a nice line like this:
<a href="https://i.sstatic.net/GAWQW.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GAWQW.png" alt="A printed &quot;Prusa Priming Line&quot;" /></a></p>
<p>In Ultimaker Cura, this piece of code is added via the preferences of a machine. In Cura 3, you usually had to add the starting G-code yourself. Since at least version 4.2.1, all preset machines contain some variant of a priming line, usually at the left side.</p>

CC BY-SA 4.0
2018-07-10T13:32:24.393Z
2019-11-06T13:51:34.637Z
2020-06-18T08:29:41.667Z
Trish
<p>Ok, I did it, I ordered myself an Ender-3, a genuine 24V e3D hotend, inductive sensor and some better tubing/clamps to cope with the problem the CR10/Ender line has occasionally.</p>

<p>But now I need to fix up my Cura for the machine coming in. The start is the CR10, and fixing the dimensions is easy.</p>

<p>But now comes the tricky part: Start and End G-code. For my TronXY I never bothered with changing it away from the "basic" settings that a "custom 3D printer" on Marlin gave, but this time I want to know what I type in there. The basic code, after I dragged out the G-code handbook from the RepRap wiki to add the missing comments is:</p>

<pre><code>G28            ;Home
G1 Z15.0 F6000 ;Move the Gantry up 15mm going fast
;Prime the extruder
G92 E0         ; reset extrusion distance
G1 F200 E3     ; extrude 3mm of feed stock
G92 E0         ; reset extrusion distance
</code></pre>

<p>The <a href="https://reprap.org/wiki/Start_GCode_routines" rel="noreferrer">RepRap Wiki</a> suggests that there could be made so much more from this. </p>

<p>I would love to <em>swipe</em> the nozzle before starting to print, making sure that the curled up filament from this first extrusion doesn't get squished against the nozzle and make a bad first layer.</p>

<p><strong>How does an example (commented) G-code for swiping the nozzle look like?</strong></p>

<ultimaker-cura><g-code>
Writing G-code : swiping at start of print
Trish
# Writing G-code : swiping at start of print

(Asked by: username_0 on 2018-07-10)

Ok, I did it, I ordered myself an Ender-3, a genuine 24V e3D hotend, inductive sensor and some better tubing/clamps to cope with the problem the CR10/Ender line has occasionally.
But now I need to fix up my Cura for the machine coming in. The start is the CR10, and fixing the dimensions is easy.
But now comes the tricky part: Start and End G-code. For my TronXY I never bothered with changing it away from the "basic" settings that a "custom 3D printer" on Marlin gave, but this time I want to know what I type in there. The basic code, after I dragged out the G-code handbook from the RepRap wiki to add the missing comments is:
G28            ;Home
G1 Z15.0 F6000 ;Move the Gantry up 15mm going fast
;Prime the extruder
G92 E0         ; reset extrusion distance
G1 F200 E3     ; extrude 3mm of feed stock
G92 E0         ; reset extrusion distance

The RepRap Wiki suggests that there could be made so much more from this. 
I would love to swipe the nozzle before starting to print, making sure that the curled up filament from this first extrusion doesn't get squished against the nozzle and make a bad first layer.
How does an example (commented) G-code for swiping the nozzle look like?

**Tags:** ultimaker-cura, g-code

---

## 5 answers

### Answer by username_0 on 2018-07-10. Score: 9 | Accepted answer

The lazy way: Skirt/Brim
With my TronXY X1 I learned pretty fast, that this first bit of extrusion on an unheated bed can totally mess up the first layer by being just in the way, as explained in the question.
To some degree, this behavior can be avoided by adding a skirt of a certain length. An equally good alternative that also increases bed adhesion for tricky parts is the brim. Both are not set via G-code but can be added by the slicer. In Ultimaker Cura both are found in the tab Build Plate Adhesion as type, as the following pictures show:
Skirt: 2 lines, minimum length 250mm

Brim: minimum length 250mm, 8mm width

The Prusa Priming-line
Angus/MakersMuse introduced me to the Prusa Priming Line in one of his tutorial videos. For his Wanhao he used (for the video) just this start G-code script:
G28
G1 Y-3 F500 ; Move out of print volume
G1 X60 E9 F500 ; start purge line
G1 X100 E12.5 F500 ; finish purge line

This resulted in a nice line like this:

In Ultimaker Cura, this piece of code is added via the preferences of a machine. In Cura 3, you usually had to add the starting G-code yourself. Since at least version 4.2.1, all preset machines contain some variant of a priming line, usually at the left side.


---

### Answer by username_5 on 2018-07-10. Score: 6

What code we have so far
The code already made by Ultimaker Cura 3 (and then commented on) can be explained a little more:
G28 ;Home
This homes your machine to hit end stop positions, from now on your printer knows the coordinates of the print volume. This place it knows as <0-0-0> - check where that is: above the print surface or next to it!
G1 Z15.0 F6000 ;Move the Gantry up 15mm going fast
Instruct the build plate to move down, or in your case lift the head up 15 mm at 6000 mm/min
;Prime the extruder
This is a comment that the nex code will deal with priming the nozzle
G92 E0 ; reset extrusion distance
G92 sets the position of the extruder by resetting the current position to the specified value of zero
G1 F200 E3 ; extrude 3mm of feed stock
This will extrude 3 mm of filament at a feedrate of 200 mm/min
G92 E0 ; reset extrusion distance
This will reset the extruder length again to zero
Result of the code
Basically you will have some filament dangling on your nozzle now, or falling of as the nozzle is hot creating a fine string. You now are facing the possibility that the primed material will be dragged along the build plate to the start of the print.
Nozzle Preparation: Priming sequences
Ultimaker 3: 'blob'&swipe
An alternative I really like is the priming sequence of the Ultimaker 3. The hot end is instructed near the origin of the printer at about a height of 2 mm above the build plate when it starts to extrude plastic, once the extruded plastic becomes a puddle of about 6 mm in diameter the build plate lowers a few mm's and keep extruding for a bit. It then moves in positive Y direction (to the back) and raises the platform (this is the swipe action), then retracts and starts to move to the print start. Now the puddle of filament stays near the origin and will not be dragged.
You can easily make a similar schematic for your printer, I've done so also for various printers. Try and experiment what works best for you. The swipe action is the movement where the nozzle will be instructed to move near the build plate while moving in a certain direction (Y or X), a height of a few tenths is enough to swipe.
I don't have my exact profile here, but you could add (skipping feedrates):
G1 Y15 Z0.2 ; moves the nozzle backwards and down from 15 mm to 0.2 mm
G1 Y20 Z0.2 ; swipes the nozzle, this should cut off the "worm"
G1 Z1     ; raise for movement to start of print to add a little space to travel


---

### Answer by username_1 on 2018-11-24. Score: 3

This is my code:
START CODE:
M117 Preparing....    ; Nozzle clean message

M140 S{material_bed_temperature_layer_0}   ; set bed temp

M107                  ; Turn layer fan off
G21                   ; Metric
G28                   ; Home X/Y/Z axis
G0 X0 Y0 Z20 F9000    ; Move up 20mm for heating

M104 S{material_print_temperature_layer_0} ; set extruder temp
M190 S{material_bed_temperature_layer_0}   ; wait for bed temp
M109 S{material_print_temperature_layer_0} ; wait for extruder temp

G92 E0                ; Zero extruder

G28                   ; Home X/Y/Z axis
G0 X1 Z0.1 F9000      ; Move up 0.1mm
G0 Y10 F500           ; Move 10mm to get rid of material
G0 Z1 F9000           ; Move up
G0 Y110 F9000         ; Move to line start
G0 Z0.2 F9000         ; Move down

G1 Y20 E25 F500       ; Extrude 25mm filament over 90mm Y axis
G1 Y10 F500           ; Move 10mm without extracting
G92 E0                ; Reset extruder
G1 E-7 F1400          ; Retract 7mm filament

M117 Printing....     ; Printing message

END CODE:
G91                   ; Incremental coordinates
G1 E-3 F1800          ; Retract
G1 Z10 F9000          ; Move up
G90                   ; Absolute cooridinates
M106 S0               ; Turn off cooling fan
M104 S0               ; Turn off extruder
M140 S0               ; Turn off bed
G1 X0 Y220 F9000      ; Move back
M84                   ; Disable motors
M117 Finished!.       ; Printing message

It's almost working perfectly. I can start prints without checking if the first layer is good (requires a leveled bed).
I am open for improvements

> **Comments:**
> **username_2**: This works well, only thing I would note is that in Slic3R I had to swap the curly braces for square brackets.  
> **username_3**: How does retracting work? Doesn't it mean that 7mm needs now to be extracted (pushed) again before it starts flowing from the nozzle?  

---

### Answer by username_0 on 2018-07-15. Score: 3

Blob & Cut
A different approach is to move to a position out off the print bed, then extrude a long piece of filament and then move forward, cutting the filament at the edge of the print surface. A sample G-code that needs to be adjusted to your bed:
G28
G1 Y-5 X5 Z0.1 F500    ; Move off the print surface, a bit above the 0
G92 E0                 ; reset extrusion distance
G1 F200 E10            ; extrude 10mm of feed stock
G92 E0                 ; reset extrusion distance
G1 Y2 F500             ; Move into the print platform


---

### Answer by username_4 on 2019-08-15. Score: 3

I've experimented a lot with priming/swiping in the G-code prologue, as a result of realizing from this question and answer how important it is to get it right. The key points are:

Don't go back and forth; you risk picking back up material you already got rid of. Just swipe in one direction.
Don't overextrude. This can lead to ending with pressure remaining (especially for printers with bowden extruders) after the swipe/prime line is finished. It's fine if your extrusion rate is so low that adhesion doesn't start til halfway down the line.
Slow movement with fan on is good.

And with that said, here's what I use with my Ender 3:
M106 ; Max fan to discourage ooze sticking to nozzle
G28 ; Home all axes
G92 E0 ; Reset Extruder
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching
G1 X0.1 Y20 Z0.3 F5000.0 ; Move to start position
G1 X0.1 Y200.0 Z0.3 F750.0 E18 ; Draw priming line
G92 E0 ; Reset Extruder
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching

I also undo all but 1mm of the filament retraction at the end of my epilogue (custom end) G-code, to leave the printer in a state comparable to having freshly loaded filament. If you don't undo the retraction here, the low extrusion rate in the prologue might not be enough to prime the next time you print, but increasing it would over-prime in the case where you're dealing with freshly loaded filament.


---

