# 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". – user77232 Nov 15 '20 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! – Quteiba ALsalaa Dec 14 '20 at 15:07

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.