<p>As far as I can recognize, the g-code file cannot be evaluated <strong>by printer firmware</strong>.</p>

<p>It is expected that slicer software will be aware of tool head selection and process tool changes according to g-code provided in an on-tool change in most slicers. </p>

<p>The best way to think about g-code (in RepRap word) is a one-way communication as the file is not treated as a script that can read and evaluate parameters on the go. (firmware capabilities).</p>

<p>references: </p>

<p><a href="https://reprap.org/wiki/G-code" rel="nofollow noreferrer">RepRap G-code list</a>
<a href="https://cdn.shopify.com/s/files/1/1069/4816/files/Pro2_Series_-_Quick_Start_Guide.pdf?15083834668884425755" rel="nofollow noreferrer">Printer quick start guide</a></p>

CC BY-SA 4.0
2018-10-05T14:10:32.793Z
@CarlWitthoft thanks for your remark & may I see an example? as per https://reprap.org/wiki/G-code, I did not find that in a  RepRap 3d printing word, also provided printer manual does not mention that. So at this stage, if the printer producer is not mentioning that in firmware capabilities I am treating that printer as a RepRap like one, therefore I am threating g-code as read-only. I edited my text to direct to firmware capabilities not GCode itself
profesor79
CC BY-SA 4.0
2018-10-05T14:16:55.290Z
and the referece here: https://cdn.shopify.com/s/files/1/1069/4816/files/Pro2_Series_-_Quick_Start_Guide.pdf?15083834668884425755
profesor79
CC BY-SA 4.0
2018-10-05T14:18:12.880Z
Ok, fair enough.  Please move your references into the answer?
Carl Witthoft
CC BY-SA 4.0
2018-10-05T19:53:44.997Z
So... The commands can't be read by the printer then? Figures. I'll just see if using a prime tower fixes my issues. I'm trying to do this with ABS/HIPS, and the print I want to get off has some complex geometry, and will take at least 8-14 hrs, so I can't run that until I'm sure it won't screw up at 50% of the way. Thanks for the help guys.
Nerevar
CC BY-SA 4.0
2018-10-05T08:42:20.913Z
2018-10-05T15:10:16.497Z
2018-10-05T15:10:16.497Z
profesor79
<p>So, I have a Raise3D Pro2, and I'm looking to perfect a tool change script for it, the goal of which is to reduce or eliminate the excess plastic that tends to build up on the nozzle when using the dual extruder. The printer uses the Marlin G-code flavor, and although I'm not sure this matters, I'm slicing in ideaMaker. The script is supposed to flow as follows:</p>

<ul>
<li>Retract current tool</li>
<li>Move to X30 Y300</li>
<li>Check if the new active tool is T0

<ul>
<li>If T0, wipe nozzle 2mm circle</li>
<li>If T0, cool T1 to 165C</li>
<li>If T0, heat T0 to 230C</li>
<li>If T0 and not layer 1, recover </li>
<li>If T0, wipe nozzle again, this time for the new tool</li>
</ul></li>
<li>Check if the new active tool is T1

<ul>
<li>If T1, wipe nozzle 2mm circle</li>
<li>If T1, cool T0 to 165C</li>
<li>If T1, heat T1 to 230C</li>
<li>If T1 and not layer 1, recover </li>
<li>If T1, wipe nozzle again, this time for the new tool</li>
</ul></li>
</ul>

<p>The current script I have looks like this:</p>

<pre><code>; extruder switch gcode start
G10 S1; Retract for current nozzle
G1 X30 Y300 F6000; Move to X:30 Y:300
[if {new_extruder}=0]; LEFT Extruder is active (T0)
[if {new_extruder}=0]G12 P2 R2; Clean inactive nozzle 2mm circle
[if {new_extruder}=0]M104 S165 T1; Cool inactive extruder to 165c (T1)
[if {new_extruder}=0]M109 S230 T0; Heat active extruder to 230c (T0) and wait.
[[if {new_extruder}=0] and [{layer_index} NE 1]]G11; Recover current nozzle when not first layer
[if {new_extruder}=0]G12 P2 R2; Clean active nozzle 2mm circle
[if {new_extruder}=1]; RIGHT Extruder is active (T1)
[if {new_extruder}=1]G12 P2 R2; Clean inactive nozzle 2mm circle
[if {new_extruder}=1]M104 S165 T0; Cool inactive extruder to 165c (T0)
[if {new_extruder}=1]M109 S230 T1; Heat active extruder to 230c (T1) and wait.
[[if {new_extruder}=1] and [{layer_index} NE 1]]G11; Recover current nozzle
[if {new_extruder}=1]G12 P2 R2; Clean active nozzle 2mm circle
; extruder switch gcode end
</code></pre>

<p>The issue is that, when I run a print with this, it doesn't seem to run all of the commands. It does the move, and the cooling/heating, but the retract/recover and nozzle wipe doesn't seem to read. I'm not sure if that's because of a printer or syntax issue, or because those commands don't work the way I think they do.</p>

<p><strong>EDIT:</strong> (by Pᴀᴜʟsᴛᴇʀ2 - Added new code and logic back in)</p>

<p>New logic:</p>

<ul>
<li>Retract current tool</li>
<li>Move to X30 Y300</li>
<li>Check if the new active tool is T0

<ul>
<li>If T0, wipe nozzle 2mm circle</li>
<li>If T0, cool T1 to 165C</li>
<li>If T0, heat T0 to 230C</li>
<li>If T0 and not layer 1, recover</li>
<li>If T0, wipe nozzle again, this time for the new tool</li>
</ul></li>
<li>Check if the new active tool is T1

<ul>
<li>If T1, wipe nozzle 2mm circle</li>
<li>If T1, cool T0 to 165C</li>
<li>If T1, heat T1 to 230C</li>
<li>If T1 and not layer 1, recover</li>
<li>If T1, wipe nozzle again, this time for the new tool</li>
</ul></li>
</ul>

<p>The new script I have looks like this:</p>

<pre><code>; extruder switch gcode start
G10 S1; Retract for current nozzle
G1 X30 Y300 F6000; Move to X:30 Y:300
[if {new_extruder}=0]; LEFT Extruder is active (T0)
[if {new_extruder}=0]G12 P2 R2; Clean inactive nozzle 2mm circle
[if {new_extruder}=0]M104 S165 T1; Cool inactive extruder to 165c (T1)
[if {new_extruder}=0]M109 S230 T0; Heat active extruder to 230c (T0) and wait.
[[if {new_extruder}=0] and [{layer_index} NE 1]]G11; Recover current nozzle when not first layer
[if {new_extruder}=0]G12 P2 R2; Clean active nozzle 2mm circle
[if {new_extruder}=1]; RIGHT Extruder is active (T1)
[if {new_extruder}=1]G12 P2 R2; Clean inactive nozzle 2mm circle
[if {new_extruder}=1]M104 S165 T0; Cool inactive extruder to 165c (T0)
[if {new_extruder}=1]M109 S230 T1; Heat active extruder to 230c (T1) and wait.
[[if {new_extruder}=1] and [{layer_index} NE 1]]G11; Recover current nozzle
[if {new_extruder}=1]G12 P2 R2; Clean active nozzle 2mm circle
; extruder switch gcode end
</code></pre>

CC BY-SA 4.0
2018-10-03T22:07:16.100Z
Welcome to 3D Printing! In your example, I'm not seeing the "S" value, which should indicate the number of repetitions of the pattern you're looking to print. I'm thinking your line should look like: **G12 P2 S1 R2 ;** (after the "if" statement, of course). Also, where is your G11 command after the G10? From [what I'm reading](http://marlinfw.org/docs/gcode/G010.html), the G10 will be ignored if it isn't followed by the G11 command.
Pᴀᴜʟsᴛᴇʀ2
CC BY-SA 4.0
2018-10-03T22:44:44.173Z
@Pᴀᴜʟsᴛᴇʀ2, The G11 is in the lines "[[if {new_extruder}=0] and [{layer_index} NE 1]]G11;", should be lines 8 and 14 in that code snippet. As for the S value, I'll give that a go and see if it changes anything.
Nerevar
CC BY-SA 4.0
2018-10-03T22:50:13.223Z
I see the G11 now ... sorry I missed it. BTW, I'm no expert on this stuff, just kinda poking around. Hope it works for you.
Pᴀᴜʟsᴛᴇʀ2
CC BY-SA 4.0
2018-10-03T22:59:53.040Z
One other thought ... if you have inactivated the nozzle, wouldn't giving it commands conflict with the assignment you've given it (ie: inactive)? (or is your comment at end of the G12 command (line 5) inaccurate and supposed to state "Clean ***active*** nozzle ...")
Pᴀᴜʟsᴛᴇʀ2
CC BY-SA 4.0
2018-10-04T14:13:28.997Z
@Pᴀᴜʟsᴛᴇʀ2 has a good point: try reorganizing so you send commands only to the currently active extruder, even if you have to  add extra  "activate" commands.
Carl Witthoft
CC BY-SA 4.0
2018-10-04T14:31:52.930Z
@Carl Witthoft I haven't gotten the chance to try it yet, but I did update the script in the code listing. I figure if I just remove those two G12's, and replace them with one that runs before it starts checking for the tools, that might work. If you or Paulster2 have any other suggestions, I'd appreciate it.
Nerevar
CC BY-SA 4.0
2018-10-04T17:01:02.787Z
BTW, please don't edit what you put originally, add it in below as a new portion and mark it as an edit. You will confuse those who are looking at the question.
Pᴀᴜʟsᴛᴇʀ2
<marlin><g-code><scripts>
Help with a Tool Change Script
Nerevar
# Help with a Tool Change Script

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

So, I have a Raise3D Pro2, and I'm looking to perfect a tool change script for it, the goal of which is to reduce or eliminate the excess plastic that tends to build up on the nozzle when using the dual extruder. The printer uses the Marlin G-code flavor, and although I'm not sure this matters, I'm slicing in ideaMaker. The script is supposed to flow as follows:

* Retract current tool
* Move to X30 Y300
* Check if the new active tool is T0
  + If T0, wipe nozzle 2mm circle
  + If T0, cool T1 to 165C
  + If T0, heat T0 to 230C
  + If T0 and not layer 1, recover
  + If T0, wipe nozzle again, this time for the new tool
* Check if the new active tool is T1
  + If T1, wipe nozzle 2mm circle
  + If T1, cool T0 to 165C
  + If T1, heat T1 to 230C
  + If T1 and not layer 1, recover
  + If T1, wipe nozzle again, this time for the new tool

The current script I have looks like this:

```
; extruder switch gcode start
G10 S1; Retract for current nozzle
G1 X30 Y300 F6000; Move to X:30 Y:300
[if {new_extruder}=0]; LEFT Extruder is active (T0)
[if {new_extruder}=0]G12 P2 R2; Clean inactive nozzle 2mm circle
[if {new_extruder}=0]M104 S165 T1; Cool inactive extruder to 165c (T1)
[if {new_extruder}=0]M109 S230 T0; Heat active extruder to 230c (T0) and wait.
[[if {new_extruder}=0] and [{layer_index} NE 1]]G11; Recover current nozzle when not first layer
[if {new_extruder}=0]G12 P2 R2; Clean active nozzle 2mm circle
[if {new_extruder}=1]; RIGHT Extruder is active (T1)
[if {new_extruder}=1]G12 P2 R2; Clean inactive nozzle 2mm circle
[if {new_extruder}=1]M104 S165 T0; Cool inactive extruder to 165c (T0)
[if {new_extruder}=1]M109 S230 T1; Heat active extruder to 230c (T1) and wait.
[[if {new_extruder}=1] and [{layer_index} NE 1]]G11; Recover current nozzle
[if {new_extruder}=1]G12 P2 R2; Clean active nozzle 2mm circle
; extruder switch gcode end

```

The issue is that, when I run a print with this, it doesn't seem to run all of the commands. It does the move, and the cooling/heating, but the retract/recover and nozzle wipe doesn't seem to read. I'm not sure if that's because of a printer or syntax issue, or because those commands don't work the way I think they do.

**EDIT:** (by username_1 - Added new code and logic back in)

New logic:

* Retract current tool
* Move to X30 Y300
* Check if the new active tool is T0
  + If T0, wipe nozzle 2mm circle
  + If T0, cool T1 to 165C
  + If T0, heat T0 to 230C
  + If T0 and not layer 1, recover
  + If T0, wipe nozzle again, this time for the new tool
* Check if the new active tool is T1
  + If T1, wipe nozzle 2mm circle
  + If T1, cool T0 to 165C
  + If T1, heat T1 to 230C
  + If T1 and not layer 1, recover
  + If T1, wipe nozzle again, this time for the new tool

The new script I have looks like this:

```
; extruder switch gcode start
G10 S1; Retract for current nozzle
G1 X30 Y300 F6000; Move to X:30 Y:300
[if {new_extruder}=0]; LEFT Extruder is active (T0)
[if {new_extruder}=0]G12 P2 R2; Clean inactive nozzle 2mm circle
[if {new_extruder}=0]M104 S165 T1; Cool inactive extruder to 165c (T1)
[if {new_extruder}=0]M109 S230 T0; Heat active extruder to 230c (T0) and wait.
[[if {new_extruder}=0] and [{layer_index} NE 1]]G11; Recover current nozzle when not first layer
[if {new_extruder}=0]G12 P2 R2; Clean active nozzle 2mm circle
[if {new_extruder}=1]; RIGHT Extruder is active (T1)
[if {new_extruder}=1]G12 P2 R2; Clean inactive nozzle 2mm circle
[if {new_extruder}=1]M104 S165 T0; Cool inactive extruder to 165c (T0)
[if {new_extruder}=1]M109 S230 T1; Heat active extruder to 230c (T1) and wait.
[[if {new_extruder}=1] and [{layer_index} NE 1]]G11; Recover current nozzle
[if {new_extruder}=1]G12 P2 R2; Clean active nozzle 2mm circle
; extruder switch gcode end

```

**Tags:** marlin, g-code, scripts

> **Comments:**
> **username_1**: Welcome to 3D Printing! In your example, I'm not seeing the "S" value, which should indicate the number of repetitions of the pattern you're looking to print. I'm thinking your line should look like: **G12 P2 S1 R2 ;** (after the "if" statement, of course). Also, where is your G11 command after the G10? From [what I'm reading](http://marlinfw.org/docs/gcode/G010.html), the G10 will be ignored if it isn't followed by the G11 command.  
> **username_0**: @username_1, The G11 is in the lines "[[if {new_extruder}=0] and [{layer_index} NE 1]]G11;", should be lines 8 and 14 in that code snippet. As for the S value, I'll give that a go and see if it changes anything.  
> **username_1**: I see the G11 now ... sorry I missed it. BTW, I'm no expert on this stuff, just kinda poking around. Hope it works for you.  
> **username_1**: One other thought ... if you have inactivated the nozzle, wouldn't giving it commands conflict with the assignment you've given it (ie: inactive)? (or is your comment at end of the G12 command (line 5) inaccurate and supposed to state "Clean ***active*** nozzle ...")  
> **username_2**: @username_1 has a good point: try reorganizing so you send commands only to the currently active extruder, even if you have to  add extra  "activate" commands.  
> **username_0**: @username_2 I haven't gotten the chance to try it yet, but I did update the script in the code listing. I figure if I just remove those two G12's, and replace them with one that runs before it starts checking for the tools, that might work. If you or Paulster2 have any other suggestions, I'd appreciate it.  
> **username_1**: BTW, please don't edit what you put originally, add it in below as a new portion and mark it as an edit. You will confuse those who are looking at the question.  

---

## 1 answers

### Answer by username_3 on 2018-10-05. Score: 3

As far as I can recognize, the g-code file cannot be evaluated **by printer firmware**.

It is expected that slicer software will be aware of tool head selection and process tool changes according to g-code provided in an on-tool change in most slicers.

The best way to think about g-code (in RepRap word) is a one-way communication as the file is not treated as a script that can read and evaluate parameters on the go. (firmware capabilities).

references:

[RepRap G-code list](https://reprap.org/wiki/G-code)
[Printer quick start guide](https://cdn.shopify.com/s/files/1/1069/4816/files/Pro2_Series_-_Quick_Start_Guide.pdf?15083834668884425755)

> **Comments:**
> **username_3**: @username_2 thanks for your remark & may I see an example? as per https://reprap.org/wiki/G-code, I did not find that in a  RepRap 3d printing word, also provided printer manual does not mention that. So at this stage, if the printer producer is not mentioning that in firmware capabilities I am treating that printer as a RepRap like one, therefore I am threating g-code as read-only. I edited my text to direct to firmware capabilities not GCode itself  
> **username_3**: and the referece here: https://cdn.shopify.com/s/files/1/1069/4816/files/Pro2_Series_-_Quick_Start_Guide.pdf?15083834668884425755  
> **username_2**: Ok, fair enough.  Please move your references into the answer?  
> **username_0**: So... The commands can't be read by the printer then? Figures. I'll just see if using a prime tower fixes my issues. I'm trying to do this with ABS/HIPS, and the print I want to get off has some complex geometry, and will take at least 8-14 hrs, so I can't run that until I'm sure it won't screw up at 50% of the way. Thanks for the help guys.  

---

