# Cleaning the nozzle every Xth layer G-code

I want to make a G-code script for Cura to clean the nozzle every Xth layer or every one minute?

With Cura there is only start and end G-code, so there is no "layer change" G-code like another slicer (e.g. Ideamaker).

Where should I write the code?

How can I define the Layer number?

• just as a side note. Is this something that you would want your printer to do automatically without needing to resort to g-code modifications? I'm asking.. er... for a "friend". Nov 15, 2020 at 17:32
• yes the Printer should do this automatically, you have to write the G-code in the Slicer (Cura) and every time you slice the written G-code will be automatic there! sometimes you have to be careful, if you change the Template the Orginal G-code will be used! just look if you still have the same G-code! Dec 14, 2020 at 15:07
• Not an answer, but if your nozzle is getting dirty during your print, it means there is a significant amount of material that came out of the extruder that did not bond where it was supposed to. This means the part was not printed right, and does not have the structural properties it should. You should probably try to figure out why that's happening and fix it, and if you do, you'll probably find that you no longer need to clean the nozzle. Aug 15, 2021 at 16:55

You need to add post-processing scripts to the Cura slicer. You do that from the top menu options Extensions -> Post Processing -> Modify G-Code and then add the option of choice.
Optionally, you could use the "ChangeAtZ" script to add absurd temperature changes of the extruder to post process that later by a simple e.g. Python script (outside Cura) to replace those actions with the cleaning actions you want to perform. But, when you can do that, you could write a script outside Cura to detect the layers (e.g. from the comments or from the layer change command G1 Zxx) and insert that right away.