Help with a Tool Change Script 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 Pᴀᴜʟsᴛᴇʀ2 - 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
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
Printer quick start guide