Skip to content

Instantly share code, notes, and snippets.

Last active February 12, 2024 15:11
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Oliv4945/6fc57ba41e442a1c0fe78b6d830da9ee to your computer and use it in GitHub Desktop.
Add regular temperature changes to a gcode file, useful for temperature towers
# -*- coding: utf-8 -*-
# Usage: python file 8 215 5
import argparse
import os
import re
parser = argparse.ArgumentParser()
parser.add_argument("file", help="Input GCode file to be parserd", type=str)
parser.add_argument("tower_steps", help="Tower steps in mm", type=int)
"temperature", help="First step temperature in degrees °C", type=int
parser.add_argument("temperature_step", help="Temperature steps in °C", type=int)
args = parser.parse_args()
# parameters
file = args.file
tower_steps_mm = args.tower_steps
temperature_c = args.temperature
temperature_step_c = args.temperature_step
# Intenal var
tower_step = 1
with open(file, "r") as file_in:
data_in = file_in.readlines()
with open(f"out_{file}", "w") as file_out:
for line in data_in:
# Capture all layer changes
# From,645652,646984#msg-646984
match ="Z(\d+\.?\d*)", line)
if match:
height =
# Add temperature change in case of multiple of tower_steps_mm
if height == f"{tower_steps_mm*tower_step}.000":
f"Height {tower_steps_mm*tower_step} mm: temperature set to {temperature_c}°C"
file_out.write(f"G10 S{temperature_c}{os.linesep}")
temperature_c -= temperature_step_c
tower_step += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment