This repository contains a Python script designed to merge two G-code files, allowing for a mid-print nozzle swap. This is ideal for printing objects that require different levels of detail in different sections, such as starting with a 0.4mm nozzle for faster base printing and switching to a 0.25mm nozzle for finer top-layer details.
- Automatic Nozzle Swap: Retracts filament, lifts the nozzle, and cools it before pausing for a safe nozzle swap.
- Customizable Transition: Choose the layer at which to switch from one nozzle to another.
- Flexible Reheat Temperature: Specify the reheat temperature to match different filament requirements.
- Safe Resumption: Automatically lowers the nozzle and resumes printing with precise positioning.
- Python 3 installed on your machine.
- Two G-code files sliced for the same object:
- One for a 0.4mm nozzle.
- One for a 0.25mm nozzle.
-
Clone this repository:
git clone https://github.com/pedrocandeias/merge-gcode-nozzle-swap.git cd merge-gcode-nozzle-swap
-
Ensure you have Python 3 installed:
python3 --version
python3 merge_gcode_nozzle_swap.py <0.4mm_gcode_file> <0.25mm_gcode_file> <output_file> [--transition <layer_number>] [--reheat_temp <temperature>]
-
Default Midpoint Transition:
python3 merge_gcode.py 3DBenchy_040n_020mm.gcode 3DBenchy_025n_015mm.gcode merged_output.gcode
-
Specify Transition Layer (e.g., at layer 60):
python3 merge_gcode.py 3DBenchy_040n_020mm.gcode 3DBenchy_025n_015mm.gcode merged_output.gcode --transition 60
-
Specify Transition Layer and Reheat Temperature:
python3 merge_gcode.py 3DBenchy_040n_020mm.gcode 3DBenchy_025n_015mm.gcode merged_output.gcode --transition 60 --reheat_temp 200
-
Setup Handling:
- The script includes setup commands from both G-code files.
-
Nozzle Swap Process:
- Retracts 5mm of filament to prevent oozing.
- Lifts the nozzle by 20mm for safe access.
- Turns off the extruder heater (
M104 S0
) to avoid burns. - Pauses the printer (
M0
) for manual nozzle swap. - After resuming, reheats the nozzle to the specified temperature (
M109 S210
by default). - Lowers the nozzle back by 20mm to continue printing.
After running the script, you will see a message similar to:
Merged G-code successfully saved to merged_output.gcode with 60 layers from the 0.4mm file and 40 layers from the 0.25mm file.
You can then preview the merged G-code in your preferred G-code viewer to ensure correctness before printing.
Feel free to fork this repository and submit pull requests with improvements or new features!
This project is licensed under the MIT License.
Pedro Candeias
Happy Printing! 🛠️💃