<p>So I think I figured this one out.  I was looking at it a bit wrong.  And here's my code:</p>
<pre><code>; Note to self:  layer_z = [layer_z]
; T tower floor 1
{if [layer_z]==1.6} M104 S225 T0
; T tower floor 2
{if [layer_z]==11.6} M104 S220 T0
; T tower floor 3
{if [layer_z]==21.6} M104 S215 T0
; T tower floor 4
{if [layer_z]==31.6} M104 S210 T0
; T tower floor 5
{if [layer_z]==41.6} M104 S205 T0
; T tower floor 6
{if [layer_z]==51.6} M104 S200 T0
; T tower floor 7
{if [layer_z]==61.6} M104 S195 T0
; T tower floor 8
{if [layer_z]==71.6} M104 S190 T0
; T tower floor 9
{if [layer_z]==81.6} M104 S185 T0
; T tower floor 10
{if [layer_z]==91.6} M104 S180 T0
</code></pre>
<p>The key to understanding what is going on is the <code>; Note to self:  layer_z = [layer_z]</code> line.  The whole block of code above gets repeated for every layer of the print in the G-code, but it gets evaluated.  And when I search for &quot;layer z =&quot; and scan thru the code.. I eventually see this...</p>
<pre><code>; Note to self:  layer_z = 1.6
; T tower floor 1
 M104 S225 T0                  &lt;---- Yowza. Nice. 
; T tower floor 2
; T tower floor 3
; T tower floor 4
; T tower floor 5
; T tower floor 6
; T tower floor 7
; T tower floor 8
; T tower floor 9
; T tower floor 10
</code></pre>
<p>and then again:</p>
<pre><code>; Note to self:  layer_z = 11.6
; T tower floor 1
; T tower floor 2
 M104 S220 T0           &lt;---- Yes!
; T tower floor 3
...
</code></pre>
<p>All good. You have to have {} and [] within the code statements...</p>
<p>Addendum:  So it turns out things are not quite perfect.  I'm noticing at the upper floors, where things should be cooler, the temperature isn't changing.  Its locked at 215C.  I see this in the code:</p>
<pre><code>; Note to self:  layer_z = 31.5999999999999      &lt;--- not sure how that happened.  
; T tower floor 1
; T tower floor 2
; T tower floor 3
; T tower floor 4
; T tower floor 5
; T tower floor 6
; T tower floor 7
; T tower floor 8
; T tower floor 9
; T tower floor 10
</code></pre>
<p><code>31.6</code> would have triggered a temperature change.  <code>31.5999999999999</code> won't do it. I need to modify the <code>{if... == }</code> to a complex test between two values...   Just wanted to share that observation here.</p>
<p>I do see from <a href="https://manual.slic3r.org/advanced/conditional-gcode" rel="nofollow noreferrer">this reference</a> that</p>
<blockquote>
<p>Expressions may be chained for an implicit AND:</p>
<p><code>{if [layer_num] == 10}{if [temperature_1] != 210}M104 S210</code></p>
</blockquote>
<p>And this seems to fix it:</p>
<pre><code>; Note to self:  layer_z = [layer_z]
; T tower floor 1
{if [layer_z]&lt;=1.65}{if [layer_z]&gt;1.55} M104 S225 T0
; T tower floor 2
{if [layer_z]&lt;=11.65}{if [layer_z]&gt;11.55} M104 S220 T0
; T tower floor 3
{if [layer_z]&lt;=21.65}{if [layer_z]&gt;21.55} M104 S215 T0
; T tower floor 4
{if [layer_z]&lt;=31.65}{if [layer_z]&gt;31.55} M104 S210 T0
; T tower floor 5
{if [layer_z]&lt;=41.65}{if [layer_z]&gt;41.55} M104 S205 T0
; T tower floor 6
{if [layer_z]&lt;=51.65}{if [layer_z]&gt;51.55} M104 S200 T0
; T tower floor 7
{if [layer_z]&lt;=61.65}{if [layer_z]&gt;61.55} M104 S195 T0
; T tower floor 8
{if [layer_z]&lt;=71.65}{if [layer_z]&gt;71.55} M104 S190 T0
; T tower floor 9
{if [layer_z]&lt;=81.65}{if [layer_z]&gt;81.55} M104 S185 T0
; T tower floor 10
{if [layer_z]&lt;=91.65}{if [layer_z]&gt;91.55} M104 S180 T0
</code></pre>

CC BY-SA 4.0
2020-04-17T13:35:27.703Z
What firmware are you using that evaluates if statements, please?
Davo
CC BY-SA 4.0
2020-04-17T13:45:42.553Z
Firmware?  I’m not sure I understand the question. I’m creating G-code using Slic3r, then inspecting the code using Atom, a piece of coding software from the folks at Github. And as for temperature problems, I’m watching the temp display as the print proceeds. Obviously something was wrong.
zipzit
CC BY-SA 4.0
2020-04-17T13:48:02.323Z
I'm asking what firmware, what flavor of processor on your 3d printer, is receiving this code and making these evaluations? When you set your slic3r recipes, what do you select  - repetier, marlin, sailboat, windchime, something else?
Davo
CC BY-SA 4.0
2020-04-17T13:58:37.700Z
Sure,  All of those details are contained [here](https://3dprinting.stackexchange.com/questions/11228/what-determines-print-start-location-on-the-build-plate/11259#11259).  It's a an older MakerBot Replicator clone, actually a Flashforge Creator 1.  Firmware upgraded to Sailfish. Start/end gcode settings see link above.   Set recipes? not sure I understand what you are asking.  Question.. why are you asking?  What part of this answer makes you curious?  (or is it the odd `31.5999999999999` value?)
zipzit
CC BY-SA 4.0
2020-04-17T18:46:46.563Z
Thanks. If you look at https://manual.slic3r.org/expert-mode/printer-settings you'll see that your Printer recipe includes a setting for what firmware you're using.
Davo
CC BY-SA 4.0
2020-04-17T21:32:16.567Z
Slic3r --> Printer Settings --> General --> Firmware, G-Code Flavor: Sailfish Makerbot   .
zipzit
CC BY-SA 4.0
2020-04-17T07:45:25.700Z
2020-04-17T09:50:20.750Z
2020-06-18T08:29:41.667Z
zipzit
<p>I watched with great interest <a href="https://www.youtube.com/watch?v=3YnB9RsMN1o" rel="nofollow noreferrer">this video: Temp Tower - Slic3r Gcode Placeholders - How To - Chris's Basement -- Jan 23, 2019    Chris Riley</a>  </p>

<p>I found a model I'm happy with: <a href="https://www.thingiverse.com/thing:2729076" rel="nofollow noreferrer">Smart compact temperature calibration tower by gaaZolee, December 24, 2017</a> Uses Layer 0.20&nbsp;mm  infill: 15&nbsp;%  </p>

<p>I'm testing a stubborn new spool of PLA.  Temp range of test 225&nbsp;&deg;C to 180&nbsp;&deg;C.  That model above came with recommended <code>if</code>statements.  I verified that with 100&nbsp;% thickness on first layer, I'm exactly hitting all the Z targets at exactly the correct place for each temperature story on the tower.  </p>

<p>I'm using the Slic3r "Printer Settings" tab - to place my <code>if</code> statements in place at "Before Layer Change G-Code".  </p>

<p>It's not clear to me on the format required for a G-Code <code>{if}</code> statement.  I've tried... </p>

<pre><code>{if layer_z == 7.8}M104 S225{endif};   // fail, this converts to: M104 S225 {endif}    
{if layer_z==1.6}M104 S225             // fail, this converts to: M104 S225    
{if [layer_z]==1.6} M104 S225          // fails, this converts to: (null)    
{if [layer_num]==8} M104 S225          // fails, this converts to: (null)    
{if layer_num==8} M104 S225          // fails, this converts to: M104 S225 
</code></pre>

<p>In detail what I'm seeing is the if statements from all ten towers prints as <em>change temp to 225, 220, 215, 210... down to 180 (last entry)</em> and 180&nbsp;&deg;C is where ALL my prints get printed at.  Total Fail. </p>

<p>I'm just not seeing anything in the Gcode output from Slic3r that remotely looks like an <code>if</code> statement.  Any ideas here?  I've seen <a href="https://manual.slic3r.org/advanced/conditional-gcode" rel="nofollow noreferrer">this reference, on advanced conditional G-Code</a> but I'm just not understanding what to do here.  </p>

<p>I do see from <a href="https://manual.slic3r.org/advanced/placeholder-parser" rel="nofollow noreferrer">Slic3r Custom G-Code Placeholder Reference</a>, that I'm using the correct terms.   <em>[layer_z] - Z height of the active layer</em>, and <em>[layer_num] - Integer number of the active layer</em>. It's not clear if their use in "Before Layer Change G-Code" require the square brackets or not.  </p>

<p>Any clues on how to get an if statement into G-Code via Slic3r for a temperature tower print?</p>

<g-code><calibration><slic3r>
Temp Tower Setup Troubles -- Slic3r (How do you format G-Code {if} statements?)
zipzit
# Temp Tower Setup Troubles -- Slic3r (How do you format G-Code {if} statements?)

(Asked by: username_0 on 2020-04-17)

I watched with great interest this video: Temp Tower - Slic3r Gcode Placeholders - How To - Chris's Basement -- Jan 23, 2019    Chris Riley 
I found a model I'm happy with: Smart compact temperature calibration tower by gaaZolee, December 24, 2017 Uses Layer 0.20 mm  infill: 15 %  
I'm testing a stubborn new spool of PLA.  Temp range of test 225 °C to 180 °C.  That model above came with recommended ifstatements.  I verified that with 100 % thickness on first layer, I'm exactly hitting all the Z targets at exactly the correct place for each temperature story on the tower.  
I'm using the Slic3r "Printer Settings" tab - to place my if statements in place at "Before Layer Change G-Code".  
It's not clear to me on the format required for a G-Code {if} statement.  I've tried... 
{if layer_z == 7.8}M104 S225{endif};   // fail, this converts to: M104 S225 {endif}    
{if layer_z==1.6}M104 S225             // fail, this converts to: M104 S225    
{if [layer_z]==1.6} M104 S225          // fails, this converts to: (null)    
{if [layer_num]==8} M104 S225          // fails, this converts to: (null)    
{if layer_num==8} M104 S225          // fails, this converts to: M104 S225 

In detail what I'm seeing is the if statements from all ten towers prints as change temp to 225, 220, 215, 210... down to 180 (last entry) and 180 °C is where ALL my prints get printed at.  Total Fail. 
I'm just not seeing anything in the Gcode output from Slic3r that remotely looks like an if statement.  Any ideas here?  I've seen this reference, on advanced conditional G-Code but I'm just not understanding what to do here.  
I do see from Slic3r Custom G-Code Placeholder Reference, that I'm using the correct terms.   [layer_z] - Z height of the active layer, and [layer_num] - Integer number of the active layer. It's not clear if their use in "Before Layer Change G-Code" require the square brackets or not.  
Any clues on how to get an if statement into G-Code via Slic3r for a temperature tower print?

**Tags:** g-code, calibration, slic3r

---

## 1 answers

### Answer by username_0 on 2020-04-17. Score: 1 | Accepted answer

So I think I figured this one out.  I was looking at it a bit wrong.  And here's my code:
; Note to self:  layer_z = [layer_z]
; T tower floor 1
{if [layer_z]==1.6} M104 S225 T0
; T tower floor 2
{if [layer_z]==11.6} M104 S220 T0
; T tower floor 3
{if [layer_z]==21.6} M104 S215 T0
; T tower floor 4
{if [layer_z]==31.6} M104 S210 T0
; T tower floor 5
{if [layer_z]==41.6} M104 S205 T0
; T tower floor 6
{if [layer_z]==51.6} M104 S200 T0
; T tower floor 7
{if [layer_z]==61.6} M104 S195 T0
; T tower floor 8
{if [layer_z]==71.6} M104 S190 T0
; T tower floor 9
{if [layer_z]==81.6} M104 S185 T0
; T tower floor 10
{if [layer_z]==91.6} M104 S180 T0

The key to understanding what is going on is the ; Note to self:  layer_z = [layer_z] line.  The whole block of code above gets repeated for every layer of the print in the G-code, but it gets evaluated.  And when I search for "layer z =" and scan thru the code.. I eventually see this...
; Note to self:  layer_z = 1.6
; T tower floor 1
 M104 S225 T0                  <---- Yowza. Nice. 
; T tower floor 2
; T tower floor 3
; T tower floor 4
; T tower floor 5
; T tower floor 6
; T tower floor 7
; T tower floor 8
; T tower floor 9
; T tower floor 10

and then again:
; Note to self:  layer_z = 11.6
; T tower floor 1
; T tower floor 2
 M104 S220 T0           <---- Yes!
; T tower floor 3
...

All good. You have to have {} and [] within the code statements...
Addendum:  So it turns out things are not quite perfect.  I'm noticing at the upper floors, where things should be cooler, the temperature isn't changing.  Its locked at 215C.  I see this in the code:
; Note to self:  layer_z = 31.5999999999999      <--- not sure how that happened.  
; T tower floor 1
; T tower floor 2
; T tower floor 3
; T tower floor 4
; T tower floor 5
; T tower floor 6
; T tower floor 7
; T tower floor 8
; T tower floor 9
; T tower floor 10

31.6 would have triggered a temperature change.  31.5999999999999 won't do it. I need to modify the {if... == } to a complex test between two values...   Just wanted to share that observation here.
I do see from this reference that

Expressions may be chained for an implicit AND:
{if [layer_num] == 10}{if [temperature_1] != 210}M104 S210

And this seems to fix it:
; Note to self:  layer_z = [layer_z]
; T tower floor 1
{if [layer_z]<=1.65}{if [layer_z]>1.55} M104 S225 T0
; T tower floor 2
{if [layer_z]<=11.65}{if [layer_z]>11.55} M104 S220 T0
; T tower floor 3
{if [layer_z]<=21.65}{if [layer_z]>21.55} M104 S215 T0
; T tower floor 4
{if [layer_z]<=31.65}{if [layer_z]>31.55} M104 S210 T0
; T tower floor 5
{if [layer_z]<=41.65}{if [layer_z]>41.55} M104 S205 T0
; T tower floor 6
{if [layer_z]<=51.65}{if [layer_z]>51.55} M104 S200 T0
; T tower floor 7
{if [layer_z]<=61.65}{if [layer_z]>61.55} M104 S195 T0
; T tower floor 8
{if [layer_z]<=71.65}{if [layer_z]>71.55} M104 S190 T0
; T tower floor 9
{if [layer_z]<=81.65}{if [layer_z]>81.55} M104 S185 T0
; T tower floor 10
{if [layer_z]<=91.65}{if [layer_z]>91.55} M104 S180 T0

> **Comments:**
> **username_1**: What firmware are you using that evaluates if statements, please?  
> **username_0**: Firmware?  I’m not sure I understand the question. I’m creating G-code using Slic3r, then inspecting the code using Atom, a piece of coding software from the folks at Github. And as for temperature problems, I’m watching the temp display as the print proceeds. Obviously something was wrong.  
> **username_1**: I'm asking what firmware, what flavor of processor on your 3d printer, is receiving this code and making these evaluations? When you set your slic3r recipes, what do you select  - repetier, marlin, sailboat, windchime, something else?  
> **username_0**: Sure,  All of those details are contained [here](https://3dprinting.stackexchange.com/questions/11228/what-determines-print-start-location-on-the-build-plate/11259#11259).  It's a an older MakerBot Replicator clone, actually a Flashforge Creator 1.  Firmware upgraded to Sailfish. Start/end gcode settings see link above.   Set recipes? not sure I understand what you are asking.  Question.. why are you asking?  What part of this answer makes you curious?  (or is it the odd `31.5999999999999` value?)  
> **username_1**: Thanks. If you look at https://manual.slic3r.org/expert-mode/printer-settings you'll see that your Printer recipe includes a setting for what firmware you're using.  
> **username_0**: Slic3r --> Printer Settings --> General --> Firmware, G-Code Flavor: Sailfish Makerbot   .  

---

