<p>Every time you see a Z movement that matches the layer height (eg. 0.20&nbsp;mm) you can assume that is the end/start of one "layer".
It should have a line like:</p>

<pre><code>;Layer count: 17
;LAYER:0.  ; mine has this as the first layer
M107
G0 F2400 X67.175 Y61.730 Z0.250. ;  moves to Z0.250 mm for the first layer, with layer thickness 0.25 mm
</code></pre>

<p>Then later:</p>

<pre><code>;LAYER:1
M106 S255
G0 F2400 X78.078 Y69.627 Z0.550 ; 2nd layer.
</code></pre>

<p>So search for "Z" or "Layer" and once you've seen 25 of these "small" movements (comparing to previous Z movement?), insert your line of code at the end of the layer commands.  Don't confuse it with large Z-movements, that may correspond to move up/retract filaments.
Depending on your goals for the print, maybe you also want to insert a wait time - say a minute or two for the new temp to stabilize?  Here is the line for that:</p>

<pre><code>G4 P200  ;  Sit still doing nothing for 200 milliseconds.
</code></pre>

CC BY-SA 4.0
2019-01-16T07:03:14.783Z
The value of Z can be found in the G-code file; if all layers are 0.2 mm, you can just look up parameter `Z5`, `Z10`, etc. in the file, there is no need to count for 25 layers. Positioning is usually absolute, not relative, for most slicers. Insertion of a dwell time (pause) is usually not necessary as the temperature steps are not that high, but nice addition if you want to be precise!
0scar
CC BY-SA 4.0
2019-01-23T07:27:42.593Z
A little math goes a long way!  Watch out for 1st layer having a different height due to adhesion options (like in my file above).
Demis
CC BY-SA 4.0
2019-01-15T05:29:11.923Z
2019-01-23T07:32:37.927Z
2019-01-23T07:32:37.927Z
Demis
<p>Under the Extensions menu in Ultimaker Cura, there's an option to add <a href="https://ultimaker.com/en/resources/20442-post-processing-plugins" rel="nofollow noreferrer">post-processing scripts</a>. One of these is called TweakAtZ, and it allows you to override certain print settings when the printer reaches a certain Z height. Multiple overrides can be specified for different heights.</p>

<p>TweakAtZ has been bundled with the standard Ultimaker Cura download for some time, but if your version doesn't have it, you can <a href="https://github.com/Dim3nsioneer/Cura-Plugins/wiki/Tweak-At-Z-plugin" rel="nofollow noreferrer">download it from GitHub</a>.</p>

CC BY-SA 4.0
2019-01-16T16:14:02.657Z
2019-01-16T19:52:28.027Z
2019-01-16T19:52:28.027Z
anaximander
<p>I want to print this <a href="https://www.thingiverse.com/thing:2213410" rel="nofollow noreferrer">heat tower calibration test</a>.</p>

<p>The instructions say to change the temperature every 25 layers. It also tells me to use G-Code command <code>M104 Sxxx</code></p>

<p>First, is there a way to specify this command using Ultimaker Cura?</p>

<p>If not, how do I do so in the G-code file? </p>

<p>I see that the G-code file is just a plain text file with a command per line presumably. Do I just insert <code>M104 S225</code> at one point and then <code>M104 S220</code>...? 
If so, how do I know where the 25th layer is?</p>

<ultimaker-cura><g-code><calibration>
How to change temperature every 25 layers (or 5 mm) in Ultimaker Cura or G-code?
kane
# How to change temperature every 25 layers (or 5 mm) in Ultimaker Cura or G-code?

(Asked by: username_0 on 2019-01-15)

I want to print this [heat tower calibration test](https://www.thingiverse.com/thing:2213410).

The instructions say to change the temperature every 25 layers. It also tells me to use G-Code command `M104 Sxxx`

First, is there a way to specify this command using Ultimaker Cura?

If not, how do I do so in the G-code file?

I see that the G-code file is just a plain text file with a command per line presumably. Do I just insert `M104 S225` at one point and then `M104 S220`...?
If so, how do I know where the 25th layer is?

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

---

## 2 answers

### Answer by username_1 on 2019-01-15. Score: 3

Every time you see a Z movement that matches the layer height (eg. 0.20 mm) you can assume that is the end/start of one "layer".
It should have a line like:
;Layer count: 17
;LAYER:0.  ; mine has this as the first layer
M107
G0 F2400 X67.175 Y61.730 Z0.250. ;  moves to Z0.250 mm for the first layer, with layer thickness 0.25 mm

Then later:
;LAYER:1
M106 S255
G0 F2400 X78.078 Y69.627 Z0.550 ; 2nd layer.

So search for "Z" or "Layer" and once you've seen 25 of these "small" movements (comparing to previous Z movement?), insert your line of code at the end of the layer commands.  Don't confuse it with large Z-movements, that may correspond to move up/retract filaments.
Depending on your goals for the print, maybe you also want to insert a wait time - say a minute or two for the new temp to stabilize?  Here is the line for that:
G4 P200  ;  Sit still doing nothing for 200 milliseconds.

> **Comments:**
> **username_2**: The value of Z can be found in the G-code file; if all layers are 0.2 mm, you can just look up parameter `Z5`, `Z10`, etc. in the file, there is no need to count for 25 layers. Positioning is usually absolute, not relative, for most slicers. Insertion of a dwell time (pause) is usually not necessary as the temperature steps are not that high, but nice addition if you want to be precise!  
> **username_1**: A little math goes a long way!  Watch out for 1st layer having a different height due to adhesion options (like in my file above).  

---

### Answer by username_3 on 2019-01-16. Score: 2

Under the Extensions menu in Ultimaker Cura, there's an option to add [post-processing scripts](https://ultimaker.com/en/resources/20442-post-processing-plugins). One of these is called TweakAtZ, and it allows you to override certain print settings when the printer reaches a certain Z height. Multiple overrides can be specified for different heights.

TweakAtZ has been bundled with the standard Ultimaker Cura download for some time, but if your version doesn't have it, you can [download it from GitHub](https://github.com/Dim3nsioneer/Cura-Plugins/wiki/Tweak-At-Z-plugin).


---

