<p>This needs to be on two lines like in your second example:</p>

<blockquote>
  <p>G4 P4000<br>
  G1 F4000 E-50</p>
</blockquote>

<p>See the RepRap Gcode Wiki for more info. <a href="https://reprap.org/wiki/G-code" rel="nofollow noreferrer">https://reprap.org/wiki/G-code</a></p>

<p>EDIT: if you actually want to retract and THEN pause, reverse it:</p>

<blockquote>
  <p>G1 F4000 E-50<br>
  G4 P4000<br></p>
</blockquote>

CC BY-SA 4.0
2018-11-14T16:10:08.363Z
That will not work, `G1` is executed after the waiting time, so now it waits, extracts filament and immediately continue, you should do it the other way around.
0scar
CC BY-SA 4.0
2018-11-14T20:25:24.730Z
Strictly speaking you are right (wait and retract), but it would be useless if the printer continues afterwards without filament after this procedure. I guess the OP needs to explain what the goal of this sequence is and where it is located in his code.
0scar
CC BY-SA 4.0
2018-11-14T16:03:53.873Z
2018-11-15T14:35:48.700Z
2018-11-15T14:35:48.700Z
Davo
<p>Yes, G-code is read line by line. G-code is a numerical control programming language. It basically instructs the machine sequentially line by line to do a specific task. The printer than executes the lines one by one until it reaches the end.</p>

<p>If you instruct the printer to wait (<code>G4</code> dwell), it will do the wait/dwell first and than will execute the next command to retract the filament. As such, your examples will not work if you want to retract the filament during the pause, you reversed the process if you want to achieve that.</p>

<p>To add a pause (simple) for e.g. filament changing, you should instruct the head to go to a certain position, extract the filament, and now insert the pause/dwell command. Give yourself enough time to insert and prime the nozzle and go back to the last location to continue printing. </p>

<p>You could insert something like (e.g. in between layer change, before <code>G1 Zx.xx</code>):</p>

<pre><code>...
G1 X0 Y0 F2000 ; Relocate the print head
G1 F4000 E-50 ; Retract filament
G4 P40000 ; Wait for 40 seconds
G92 E50 ; The new filament should continue at this value
...
G1 Zx.xx
</code></pre>

<p>Depending on what happens after <code>G1 Zx.xx</code>, you may need to set the head back to the location prior to where it was before <code>G1 X0 Y0 F2000</code>.</p>

<p>Do note that there are pausing scripts/plugins available for e.g. Ultimaker Cura, and there is also a filament changing command <a href="https://reprap.org/wiki/G-code#M600:_Filament_change_pause" rel="nofollow noreferrer"><code>M600</code></a> that can be enabled for certain firmware (if this is your ultimate goal).</p>

<p>Using a post processing plugin of Ultimaker Cura, a pausing script looks like:</p>

<pre>
...
G0 X137.692 Y105
;TIME_ELAPSED:707.873599
;TYPE:CUSTOM;added code by post processing
;script: PauseAtHeight.py
;current z: 5
;current height: 5.0
M83
G1 F300 Z6
G1 F9000 X190 Y190
G1 F300 Z15
M104 S0; standby temperature
M0;Do the actual pause
M109 S200; resume temperature
G1 F300 Z6
G1 F9000 X133.423 Y105
G1 F9000
M82
G92 E911.50045
;LAYER:24
G0 X137.692 Y105 Z5
...
</pre>

<p>Note that <code>G0</code> and <code>G1</code> are <em>"move to"</em> location instructions (albeit through a different way, fast move and linear move respectively). If you look closely, you see that after the pause, the printer returns to the X-Y position where it left prior to the pause (<code>X137.692 Y105</code>).</p>

<hr>

<p><em>Side note:<br>
Some firmware flavors allow <a href="https://reprap.org/wiki/G-code#Buffering" rel="nofollow noreferrer">buffering</a>, but each statement is executed sequentially.</em></p>

CC BY-SA 4.0
2018-11-14T16:07:03.010Z
2018-12-13T06:59:12.927Z
2018-12-13T06:59:12.927Z
0scar
<p>I am trying to add the line</p>

<blockquote>
  <p>G4 P4000 G1 F4000 E-50</p>
</blockquote>

<p>to pause and retract the print in order for the printed line to dry (printing in mid air vertically). Does the above code work or should i skip lines or does it not matter at all?</p>

<blockquote>
  <p>G4 P4000<br>
  G1 F4000 E-50</p>
</blockquote>

<p>Would the following line do the exact same thing?</p>

<blockquote>
  <p>G4 P5000 E-50</p>
</blockquote>

CC BY-SA 4.0
2018-11-14T16:50:13.457Z
Basically,  only one "Gx" command per line. Everything following is a parameter list modifying the command.
Carl Witthoft
CC BY-SA 4.0
2018-11-14T20:16:13.607Z
Maybe you should update the question to explain what you exactly want to do, e.g. do you want to change to another filament, e.g. do you pause to retract during the pause? As it stands now the print pauses, you retract the filament after the pause and then the print continues without filament when inserted in between the code lines. Please explain where the pause is taking place.
0scar
<g-code>
Is G-code read line by line?
Arthur Mamou-Mani
# Is G-code read line by line?

(Asked by: username_0 on 2018-11-14)

I am trying to add the line

> G4 P4000 G1 F4000 E-50

to pause and retract the print in order for the printed line to dry (printing in mid air vertically). Does the above code work or should i skip lines or does it not matter at all?

> G4 P4000  
> G1 F4000 E-50

Would the following line do the exact same thing?

> G4 P5000 E-50

**Tags:** g-code

> **Comments:**
> **username_1**: Basically,  only one "Gx" command per line. Everything following is a parameter list modifying the command.  
> **username_2**: Maybe you should update the question to explain what you exactly want to do, e.g. do you want to change to another filament, e.g. do you pause to retract during the pause? As it stands now the print pauses, you retract the filament after the pause and then the print continues without filament when inserted in between the code lines. Please explain where the pause is taking place.  

---

## 2 answers

### Answer by username_2 on 2018-11-14. Score: 8 | Accepted answer

Yes, G-code is read line by line. G-code is a numerical control programming language. It basically instructs the machine sequentially line by line to do a specific task. The printer than executes the lines one by one until it reaches the end.

If you instruct the printer to wait (`G4` dwell), it will do the wait/dwell first and than will execute the next command to retract the filament. As such, your examples will not work if you want to retract the filament during the pause, you reversed the process if you want to achieve that.

To add a pause (simple) for e.g. filament changing, you should instruct the head to go to a certain position, extract the filament, and now insert the pause/dwell command. Give yourself enough time to insert and prime the nozzle and go back to the last location to continue printing.

You could insert something like (e.g. in between layer change, before `G1 Zx.xx`):

```
...
G1 X0 Y0 F2000 ; Relocate the print head
G1 F4000 E-50 ; Retract filament
G4 P40000 ; Wait for 40 seconds
G92 E50 ; The new filament should continue at this value
...
G1 Zx.xx

```

Depending on what happens after `G1 Zx.xx`, you may need to set the head back to the location prior to where it was before `G1 X0 Y0 F2000`.

Do note that there are pausing scripts/plugins available for e.g. Ultimaker Cura, and there is also a filament changing command [`M600`](https://reprap.org/wiki/G-code#M600:_Filament_change_pause) that can be enabled for certain firmware (if this is your ultimate goal).

Using a post processing plugin of Ultimaker Cura, a pausing script looks like:

```

...
G0 X137.692 Y105
;TIME_ELAPSED:707.873599
;TYPE:CUSTOM;added code by post processing
;script: PauseAtHeight.py
;current z: 5
;current height: 5.0
M83
G1 F300 Z6
G1 F9000 X190 Y190
G1 F300 Z15
M104 S0; standby temperature
M0;Do the actual pause
M109 S200; resume temperature
G1 F300 Z6
G1 F9000 X133.423 Y105
G1 F9000
M82
G92 E911.50045
;LAYER:24
G0 X137.692 Y105 Z5
...

```

Note that `G0` and `G1` are *"move to"* location instructions (albeit through a different way, fast move and linear move respectively). If you look closely, you see that after the pause, the printer returns to the X-Y position where it left prior to the pause (`X137.692 Y105`).

---

*Side note:  
Some firmware flavors allow [buffering](https://reprap.org/wiki/G-code#Buffering), but each statement is executed sequentially.*


---

### Answer by username_3 on 2018-11-14. Score: 4

This needs to be on two lines like in your second example:

> G4 P4000  
> G1 F4000 E-50

See the RepRap Gcode Wiki for more info. <https://reprap.org/wiki/G-code>

EDIT: if you actually want to retract and THEN pause, reverse it:

> G1 F4000 E-50  
> G4 P4000

> **Comments:**
> **username_2**: That will not work, `G1` is executed after the waiting time, so now it waits, extracts filament and immediately continue, you should do it the other way around.  
> **username_2**: Strictly speaking you are right (wait and retract), but it would be useless if the printer continues afterwards without filament after this procedure. I guess the OP needs to explain what the goal of this sequence is and where it is located in his code.  

---

