3D Pilot
← Back to tips
Advanced

Macros in Klipper – Print Automation

Macros in Klipper – Print Automation image

Automate routine tasks with Klipper macros and G-code scripts.

Klipper macros are scripts that execute on command or automatically:

🔧 Basic macro syntax:
[gcode_macro START_PRINT]
gcode:
  G28                    ; Home all axes
  BED_MESH_CALIBRATE     ; Auto bed leveling
  G1 Z5 F3000            ; Raise Z-axis
  M109 S{params.TEMP}    ; Wait for temperature

🚀 Most useful macros: • START_PRINT – preheat, homing, leveling, purge line • END_PRINT – retraction, cooling, head parking • CANCEL_PRINT – safe stop • FILAMENT_CHANGE (M600) – pause for color change • PID_TUNE – automatic temperature calibration

💡 Advanced Jinja2 features: • Variables: {% set temp = params.TEMP|int %} • Conditions: {% if printer.extruder.temperature > 170 %} • Loops: {% for i in range(3) %} • Calling other macros: _PURGE_LINE

📦 Recommended macro collections: • KAMP – purge line adapts to print area only • Happy Hare – for MMU systems • Mainsail/Fluidd – built-in macros for UI

⚠️ Always test new macros with hand on E-stop.