Static mesh - Phil1988/FreeDi GitHub Wiki
Default in this project is adaptive meshing (KAMP-style): it creates a bed mesh only for the area that is actually used by the current print job, instead of probing the full bed.
Klipper v0.13 also introduced a native adaptive approach comparable to KAMP (so “adaptive meshing” is no longer strictly an external add-on concept).
Note
This is not mandatory.
This may only be relevant for you if you dont want to use an adaptive mesh
A static mesh can be useful if you want to start prints faster (“YOLO style” because the bed is not re-probed precisely each job), or if you have general issues with your probe/sensor or adaptive meshing and want to compensate with one well-made mesh.
This feature was requested as an option (see: https://github.com/Phil1988/FreeDi/issues/347).
At the moment, using the static mesh is only possible from the printer display (LCD).
Steps: File Explorer → select print file → in the preview disable the KAMP toggle.
- You need to have created a STATIC_MESH (see section “Create the STATIC_MESH” below)
- You need a working macro setup (see section “Macros” below).
- Your slicer must not force adaptive meshing every time (see “Slicer settings”).
To create the mesh,
-
Open Mainsail → HEIGHTMAP.
-
Click the Home (house) icon to home the printer.
-
Click CALIBRATE to probe the mesh.

-
When prompted for a profile name, you must use:
STATIC_MESH(this name is required so the macro can find it).

-
Wait until the meshing finishes. Then, click on SAVE CONFIG to store it to your printer.cfg.

After klipper restarted, you should be able to see the created STATIC_MESH on the right side.
You can visualise it using the "load mesh" icon:

If you did a very poor job like I did for the purpose of this guide, you will see something like this ;)

Open your slicer and inspect the Start G-code.
Example for reference on Orca Slicer:

Many slicers/printer-profiles automatically trigger bed leveling actions; we must ensure they do not always generate an adaptive mesh.
- If you see something like
G29, remove or disable it (printer-dependent). - If you see something like
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1, it will force adaptive probing via Klipper’s adaptive calibration parameter and should be removed/disabled for static-mesh usage. - Recommendation: comment it out instead of deleting it, e.g. prepend
;so you can restore it later.
Example (commented out):
; G29; mesh bed leveling ,comment this code to close itOR
; BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1These are examples that were current at the time this wiki page was written, but they can change regularly.
The up-to-date configuration examples can always be found here: https://github.com/Phil1988/FreeDi/tree/master/config_section
Make sure to see the device specifig examples below.
Add this to your macros.cfg (if it does not exist yet).
It sets a flag so the next print uses the stored STATIC_MESH profile instead of adaptive meshing.
# Flag macro to use STATIC_MESH usage instead of KAMP (needed make this function work from printjob selection on the LCD)
[gcode_macro NEXT_PRINT_STATIC_MESH]
description: Forces the NEXT print to use 'STATIC_MESH' instead of KAMP.
gcode:
{% if "STATIC_MESH" in printer.bed_mesh.profiles %}
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=force_static_mesh VALUE=True
{action_respond_info("The NEXT print will use 'STATIC_MESH'.")}
M118 The NEXT print will use the STATIC_MESH.
{% else %}
{action_respond_info("WARNING: No mesh named 'STATIC_MESH' found. Please save one first (BED_MESH_PROFILE SAVE=STATIC_MESH).")}
M118 WARNING: No mesh named STATIC_MESH found. Please save one first (BED_MESH_PROFILE SAVE=STATIC_MESH).
{% endif %}Your PRINT_START macro must have:
- A variable flag (
variable_force_static_mesh) - Logic to load
STATIC_MESHwhen the flag is set, otherwise do normal adaptive meshing
Insert this after:
description: Start printing
and before:
gcode:
[gcode_macro PRINT_START]
# Use PRINT_START for the slicer starting script
description: Start printing
variable_force_static_mesh: False ; <--- Add this line. Set to True to force a static mesh instead of KAMP
gcode:Insert this after:
SET_TEMPERATURE_FAN_TARGET TEMPERATURE_FAN=Mainboard_fan TARGET=1
{% set KAMP_deactivated = printer["gcode_macro PRINT_START"].force_static_mesh %} ; Check if KAMP is deactivated for this print
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=force_static_mesh VALUE=False ; Auto-reset the variable immediately for the next print after this oneInsert this after the bed has been heated (exact position depends on your PRINT_START flow):
{% if KAMP_deactivated %}
{% if "STATIC_MESH" in printer.bed_mesh.profiles %} ; Check if the spicific STATIC_MESH exists
M118 Loading 'STATIC_MESH' instead of KAMP.
BED_MESH_PROFILE LOAD=STATIC_MESH
{% else %} ; Fallback to KAMP if STATIC_MESH not found
M118 ERROR: 'STATIC_MESH' not found! Using fallback: KAMP Adaptive Mesh.
BED_MESH_CLEAR ; Clear previous adaptive mesh
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1 ; Start adaptive meshing
{% endif %}
{% else %} ; Standard operation
{% if printer.toolhead.homed_axes|length < 3 %}
G28
{% endif %}
BED_MESH_CLEAR ; Clear previous adaptive mesh
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1 ; Start adaptive meshing
{% endif %}GCODE (X-Smart3)
# Flag macro to use STATIC_MESH usage instead of KAMP (needed make this function work from printjob selection on the LCD)
[gcode_macro NEXT_PRINT_STATIC_MESH]
description: Forces the NEXT print to use 'STATIC_MESH' instead of KAMP.
gcode:
{% if "STATIC_MESH" in printer.bed_mesh.profiles %}
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=force_static_mesh VALUE=True
{action_respond_info("The NEXT print will use 'STATIC_MESH'.")}
M118 The NEXT print will use the STATIC_MESH.
{% else %}
{action_respond_info("WARNING: No mesh named 'STATIC_MESH' found. Please save one first (BED_MESH_PROFILE SAVE=STATIC_MESH).")}
M118 WARNING: No mesh named STATIC_MESH found. Please save one first (BED_MESH_PROFILE SAVE=STATIC_MESH).
{% endif %}
[gcode_macro PRINT_START]
# Use PRINT_START for the slicer starting script
description: Start printing
variable_force_static_mesh: False ; Set to True to force a static mesh instead of KAMP
gcode:
{% set bed_target_temp = params.BED|default(0)|int %}
{% set hotend_target_temp = params.HOTEND|default(0)|int %}
{% set in_advanced_mode = (bed_target_temp > 0) or (hotend_target_temp > 0)%}
CLEAR_PAUSE ; Clear existing pause states
BED_MESH_CLEAR ; Clear previous adaptive mesh
SET_TEMPERATURE_FAN_TARGET TEMPERATURE_FAN=Mainboard_fan TARGET=1 ; Decrease the mainboard target temp to fully turn the fan on
{% set KAMP_deactivated = printer["gcode_macro PRINT_START"].force_static_mesh %} ; Check if KAMP is deactivated for this print
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=force_static_mesh VALUE=False ; Auto-reset the variable immediately for the next print after this one
{% if in_advanced_mode %}
{% set bed_center_x = printer.configfile.config["stepper_x"]["position_max"]|float / 2 %}
{% set bed_center_y = printer.configfile.config["stepper_y"]["position_max"]|float / 2 %}
{% set start_position_x = printer.toolhead.axis_maximum.x / 2 %}
{% set start_position_y = printer.toolhead.axis_maximum.y - 40 %}
{% set start_position_z = 10 %}
M140 S{bed_target_temp} ; Set bed temperature
G28 ; Home all axes
G90 ; Set absolute positioning
G1 X{start_position_x} Y{start_position_y} Z{start_position_z} F7800 ; Move to start position
G28 Z ; Home Z again for to compensate bed expansion
{% endif %}
{% if KAMP_deactivated %}
{% if "STATIC_MESH" in printer.bed_mesh.profiles %} ; Check if the spicific STATIC_MESH exists
M118 Loading 'STATIC_MESH' instead of KAMP.
BED_MESH_PROFILE LOAD=STATIC_MESH
{% else %} ; Fallback to KAMP if STATIC_MESH not found
M118 ERROR: 'STATIC_MESH' not found! Using fallback: KAMP Adaptive Mesh.
BED_MESH_CLEAR ; Clear previous adaptive mesh
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1 ; Start adaptive meshing
{% endif %}
{% else %} ; Standard operation
{% if printer.toolhead.homed_axes|length < 3 %}
G28
{% endif %}
BED_MESH_CLEAR ; Clear previous adaptive mesh
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1 ; Start adaptive meshing
{% endif %}
{% if in_advanced_mode %}
M109 S{hotend_target_temp} ; Set and wait for hotend temperature
{% endif %}GCODE (X-Plus3)
# Flag macro to use STATIC_MESH usage instead of KAMP (needed make this function work from printjob selection on the LCD)
[gcode_macro NEXT_PRINT_STATIC_MESH]
description: Forces the NEXT print to use 'STATIC_MESH' instead of KAMP.
gcode:
{% if "STATIC_MESH" in printer.bed_mesh.profiles %}
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=force_static_mesh VALUE=True
{action_respond_info("The NEXT print will use 'STATIC_MESH'.")}
M118 The NEXT print will use the STATIC_MESH.
{% else %}
{action_respond_info("WARNING: No mesh named 'STATIC_MESH' found. Please save one first (BED_MESH_PROFILE SAVE=STATIC_MESH).")}
M118 WARNING: No mesh named STATIC_MESH found. Please save one first (BED_MESH_PROFILE SAVE=STATIC_MESH).
{% endif %}
[gcode_macro PRINT_START]
# Use PRINT_START for the slicer starting script
description: Start printing
variable_force_static_mesh: False ; Set to True to force a static mesh instead of KAMP
gcode:
{% set bed_target_temp = params.BED|default(0)|int %}
{% set hotend_target_temp = params.HOTEND|default(0)|int %}
{% set chamber_target_temp = params.CHAMBER|default(0)|int %}
{% set in_advanced_mode = (bed_target_temp > 0) or (hotend_target_temp > 0) or (chamber_target_temp > 0) %}
CLEAR_PAUSE ; Clear existing pause states
BED_MESH_CLEAR ; Clear previous adaptive mesh
SET_TEMPERATURE_FAN_TARGET TEMPERATURE_FAN=Mainboard_fan TARGET=1 ; Decrease the mainboard target temp to fully turn the fan on
{% set KAMP_deactivated = printer["gcode_macro PRINT_START"].force_static_mesh %} ; Check if KAMP is deactivated for this print
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=force_static_mesh VALUE=False ; Auto-reset the variable immediately for the next print after this one
{% if in_advanced_mode %}
{% set bed_center_x = printer.configfile.config["stepper_x"]["position_max"]|float / 2 %}
{% set bed_center_y = printer.configfile.config["stepper_y"]["position_max"]|float / 2 %}
{% set start_position_x = printer.toolhead.axis_maximum.x / 2 %}
{% set start_position_y = printer.toolhead.axis_maximum.y - 40 %}
{% set start_position_z = 10 %}
M140 S{bed_target_temp} ; Set bed temperature
M141 S{chamber_target_temp} ; Set chamber temperature
G28 ; Home all axes
{% if chamber_target_temp > 0 %} ; Accelerate chamber heating by using the bed as additional heater
G0 X{bed_center_x} Y{bed_center_y} Z3 F780 ; Move print bed to perfect postion to help chamber heating
M106 P2 S185 ; Turn sidefan on to use bed heat and mix air
M106 P0 S128 ; Turn part cooling fan on to help air mixing
TEMPERATURE_WAIT SENSOR="heater_generic chamber" MINIMUM={chamber_target_temp - 5} ; Wait for chamber to heat up
M106 P2 S0 ; Turn off sidefan
M106 P0 S0 ; Turn off part cooling fan
{% endif %}
M191 S{chamber_target_temp} ; Set and wait for chamber temperature
M190 S{bed_target_temp} ; Set and wait for bed temperature
G90 ; Set absolute positioning
G1 X{start_position_x} Y{start_position_y} Z{start_position_z} F7800 ; Move to start position
G28 Z ; Home Z again for to compensate bed expansion
{% endif %}
{% if KAMP_deactivated %}
{% if "STATIC_MESH" in printer.bed_mesh.profiles %} ; Check if the spicific STATIC_MESH exists
M118 Loading 'STATIC_MESH' instead of KAMP.
BED_MESH_PROFILE LOAD=STATIC_MESH
{% else %} ; Fallback to KAMP if STATIC_MESH not found
M118 ERROR: 'STATIC_MESH' not found! Using fallback: KAMP Adaptive Mesh.
BED_MESH_CLEAR ; Clear previous adaptive mesh
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1 ; Start adaptive meshing
{% endif %}
{% else %} ; Standard operation
{% if printer.toolhead.homed_axes|length < 3 %}
G28
{% endif %}
BED_MESH_CLEAR ; Clear previous adaptive mesh
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1 ; Start adaptive meshing
{% endif %}
{% if in_advanced_mode %}
M109 S{hotend_target_temp} ; Set and wait for hotend temperature
{% endif %}GCODE (X-Max3)
# Flag macro to use STATIC_MESH usage instead of KAMP (needed make this function work from printjob selection on the LCD)
[gcode_macro NEXT_PRINT_STATIC_MESH]
description: Forces the NEXT print to use 'STATIC_MESH' instead of KAMP.
gcode:
{% if "STATIC_MESH" in printer.bed_mesh.profiles %}
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=force_static_mesh VALUE=True
{action_respond_info("The NEXT print will use 'STATIC_MESH'.")}
M118 The NEXT print will use the STATIC_MESH.
{% else %}
{action_respond_info("WARNING: No mesh named 'STATIC_MESH' found. Please save one first (BED_MESH_PROFILE SAVE=STATIC_MESH).")}
M118 WARNING: No mesh named STATIC_MESH found. Please save one first (BED_MESH_PROFILE SAVE=STATIC_MESH).
{% endif %}
[gcode_macro PRINT_START]
# Use PRINT_START for the slicer starting script
description: Start printing
variable_force_static_mesh: False ; Set to True to force a static mesh instead of KAMP
gcode:
{% set bed_target_temp = params.BED|default(0)|int %}
{% set hotend_target_temp = params.HOTEND|default(0)|int %}
{% set chamber_target_temp = params.CHAMBER|default(0)|int %}
{% set in_advanced_mode = (bed_target_temp > 0) or (hotend_target_temp > 0) or (chamber_target_temp > 0) %}
CLEAR_PAUSE ; Clear existing pause states
BED_MESH_CLEAR ; Clear previous adaptive mesh
SET_TEMPERATURE_FAN_TARGET TEMPERATURE_FAN=Mainboard_fan TARGET=1 ; Decrease the mainboard target temp to fully turn the fan on
{% set KAMP_deactivated = printer["gcode_macro PRINT_START"].force_static_mesh %} ; Check if KAMP is deactivated for this print
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=force_static_mesh VALUE=False ; Auto-reset the variable immediately for the next print after this one
{% if in_advanced_mode %}
{% set bed_center_x = printer.configfile.config["stepper_x"]["position_max"]|float / 2 %}
{% set bed_center_y = printer.configfile.config["stepper_y"]["position_max"]|float / 2 %}
{% set start_position_x = printer.toolhead.axis_maximum.x / 2 %}
{% set start_position_y = printer.toolhead.axis_maximum.y - 40 %}
{% set start_position_z = 10 %}
M140 S{bed_target_temp} ; Set bed temperature
M141 S{chamber_target_temp} ; Set chamber temperature
G28 ; Home all axes
{% if chamber_target_temp > 0 %} ; Accelerate chamber heating by using the bed as additional heater
G0 X{bed_center_x} Y{bed_center_y} Z3 F780 ; Move print bed to perfect postion to help chamber heating
M106 P2 S185 ; Turn sidefan on to use bed heat and mix air
M106 P0 S128 ; Turn part cooling fan on to help air mixing
TEMPERATURE_WAIT SENSOR="heater_generic chamber" MINIMUM={chamber_target_temp - 5} ; Wait for chamber to heat up
M106 P2 S0 ; Turn off sidefan
M106 P0 S0 ; Turn off part cooling fan
{% endif %}
M191 S{chamber_target_temp} ; Set and wait for chamber temperature
M190 S{bed_target_temp} ; Set and wait for bed temperature
G90 ; Set absolute positioning
G1 X{start_position_x} Y{start_position_y} Z{start_position_z} F7800 ; Move to start position
G28 Z ; Home Z again for to compensate bed expansion
{% endif %}
{% if KAMP_deactivated %}
{% if "STATIC_MESH" in printer.bed_mesh.profiles %} ; Check if the spicific STATIC_MESH exists
M118 Loading 'STATIC_MESH' instead of KAMP.
BED_MESH_PROFILE LOAD=STATIC_MESH
{% else %} ; Fallback to KAMP if STATIC_MESH not found
M118 ERROR: 'STATIC_MESH' not found! Using fallback: KAMP Adaptive Mesh.
BED_MESH_CLEAR ; Clear previous adaptive mesh
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1 ; Start adaptive meshing
{% endif %}
{% else %} ; Standard operation
{% if printer.toolhead.homed_axes|length < 3 %}
G28
{% endif %}
BED_MESH_CLEAR ; Clear previous adaptive mesh
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1 ; Start adaptive meshing
{% endif %}
{% if in_advanced_mode %}
M109 S{hotend_target_temp} ; Set and wait for hotend temperature
{% endif %}GCODE (Q1 Pro)
# Flag macro to use STATIC_MESH usage instead of KAMP (needed make this function work from printjob selection on the LCD)
[gcode_macro NEXT_PRINT_STATIC_MESH]
description: Forces the NEXT print to use 'STATIC_MESH' instead of KAMP.
gcode:
{% if "STATIC_MESH" in printer.bed_mesh.profiles %}
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=force_static_mesh VALUE=True
{action_respond_info("The NEXT print will use 'STATIC_MESH'.")}
M118 The NEXT print will use the STATIC_MESH.
{% else %}
{action_respond_info("WARNING: No mesh named 'STATIC_MESH' found. Please save one first (BED_MESH_PROFILE SAVE=STATIC_MESH).")}
M118 WARNING: No mesh named STATIC_MESH found. Please save one first (BED_MESH_PROFILE SAVE=STATIC_MESH).
{% endif %}
[gcode_macro PRINT_START]
# Use PRINT_START for the slicer starting script
description: Start printing
variable_force_static_mesh: False ; Set to True to force a static mesh instead of KAMP
gcode:
{% set bed_target_temp = params.BED|int %}
{% set hotend_target_temp = params.HOTEND|int %}
{% set chamber_target_temp = params.CHAMBER|default(0)|int %}
{% set bed_center_x = printer.configfile.config["stepper_x"]["position_max"]|float / 2 %}
{% set bed_center_y = printer.configfile.config["stepper_y"]["position_max"]|float / 2 %}
{% set start_position_x = printer.toolhead.axis_maximum.x / 2 %}
{% set start_position_y = printer.toolhead.axis_maximum.y - 40 %}
{% set start_position_z = 10 %}
CLEAR_PAUSE ; Clear existing pause states
BED_MESH_CLEAR ; Clear previous adaptive mesh
SET_TEMPERATURE_FAN_TARGET TEMPERATURE_FAN=Mainboard_fan TARGET=1 ; Decrease the mainboard target temp to fully turn the fan on
{% set KAMP_deactivated = printer["gcode_macro PRINT_START"].force_static_mesh %} ; Check if KAMP is deactivated for this print
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=force_static_mesh VALUE=False ; Auto-reset the variable immediately for the next print after this one
M140 S{bed_target_temp}
M141 S{chamber_target_temp}
G28
{% if chamber_target_temp > 0 %} ; Accelerate chamber heating by using the bed as additional heater
G0 X{bed_center_x} Y{bed_center_y} Z3 F780 ; Move print bed to perfect postion to help chamber heating
M106 P2 S185 ; Turn sidefan on to use bed heat and mix air
M106 P0 S128 ; Turn part cooling fan on to help air mixing
TEMPERATURE_WAIT SENSOR="heater_generic chamber" MINIMUM={chamber_target_temp - 5} ; Wait for chamber to heat up
M106 P2 S0 ; Turn off sidefan
M106 P0 S0 ; Turn off part cooling fan
{% endif %}
{% if bed_target_temp !=0 %}
TEMPERATURE_WAIT SENSOR=heater_bed MINIMUM={bed_target_temp * 0.95} MAXIMUM={bed_target_temp * 1.05}
{% endif %}
M191 S{chamber_target_temp} ; Set and wait for chamber temperature
M190 S{bed_target_temp} ; Set and wait for bed temperature
G90 ; Set absolute positioning
G1 X{start_position_x} Y{start_position_y} Z{start_position_z} F7800 ; Move to start position
G28 Z ; Home Z again for to compensate bed expansion
{% if KAMP_deactivated %}
{% if "STATIC_MESH" in printer.bed_mesh.profiles %} ; Check if the spicific STATIC_MESH exists
M118 Loading 'STATIC_MESH' instead of KAMP.
BED_MESH_PROFILE LOAD=STATIC_MESH
{% else %} ; Fallback to KAMP if STATIC_MESH not found
M118 ERROR: 'STATIC_MESH' not found! Using fallback: KAMP Adaptive Mesh.
BED_MESH_CLEAR ; Clear previous adaptive mesh
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1 ; Start adaptive meshing
{% endif %}
{% else %} ; Standard operation
{% if printer.toolhead.homed_axes|length < 3 %}
G28
{% endif %}
BED_MESH_CLEAR ; Clear previous adaptive mesh
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1 ; Start adaptive meshing
{% endif %}
PRIME_NOZZLE hotend_target_temp={hotend_target_temp}
M109 S{hotend_target_temp} ; Set and wait for hotend temperature GCODE (Plus4)
# Flag macro to use STATIC_MESH usage instead of KAMP (needed make this function work from printjob selection on the LCD)
[gcode_macro NEXT_PRINT_STATIC_MESH]
description: Forces the NEXT print to use 'STATIC_MESH' instead of KAMP.
gcode:
{% if "STATIC_MESH" in printer.bed_mesh.profiles %}
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=force_static_mesh VALUE=True
{action_respond_info("The NEXT print will use 'STATIC_MESH'.")}
M118 The NEXT print will use the STATIC_MESH.
{% else %}
{action_respond_info("WARNING: No mesh named 'STATIC_MESH' found. Please save one first (BED_MESH_PROFILE SAVE=STATIC_MESH).")}
M118 WARNING: No mesh named STATIC_MESH found. Please save one first (BED_MESH_PROFILE SAVE=STATIC_MESH).
{% endif %}
[gcode_macro PRINT_START]
# Use PRINT_START for the slicer starting script
description: Start printing
variable_force_static_mesh: False ; Set to True to force a static mesh instead of KAMP
gcode:
{% set bed_target_temp = params.BED|int %}
{% set hotend_target_temp = params.HOTEND|int %}
{% set chamber_target_temp = params.CHAMBER|default(0)|int %}
{% set bed_center_x = printer.configfile.config["stepper_x"]["position_max"]|float / 2 %}
{% set bed_center_y = printer.configfile.config["stepper_y"]["position_max"]|float / 2 %}
{% set start_position_x = printer.toolhead.axis_maximum.x / 2 %}
{% set start_position_y = printer.toolhead.axis_maximum.y - 40 %}
{% set start_position_z = 10 %}
CLEAR_PAUSE ; Clear existing pause states
BED_MESH_CLEAR ; Clear previous adaptive mesh
SET_TEMPERATURE_FAN_TARGET TEMPERATURE_FAN=Mainboard_fan TARGET=1 ; Decrease the mainboard target temp to fully turn the fan on
{% set KAMP_deactivated = printer["gcode_macro PRINT_START"].force_static_mesh %} ; Check if KAMP is deactivated for this print
SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=force_static_mesh VALUE=False ; Auto-reset the variable immediately for the next print after this one
M140 S{bed_target_temp}
M141 S{chamber_target_temp}
G28
{% if chamber_target_temp > 0 %} ; Accelerate chamber heating by using the bed as additional heater
G0 X{bed_center_x} Y{bed_center_y} Z3 F780 ; Move print bed to perfect postion to help chamber heating
M106 P2 S185 ; Turn sidefan on to use bed heat and mix air
M106 P0 S128 ; Turn part cooling fan on to help air mixing
TEMPERATURE_WAIT SENSOR="heater_generic chamber" MINIMUM={chamber_target_temp - 5} ; Wait for chamber to heat up
M106 P2 S0 ; Turn off sidefan
M106 P0 S0 ; Turn off part cooling fan
{% endif %}
{% if bed_target_temp !=0 %}
TEMPERATURE_WAIT SENSOR=heater_bed MINIMUM={bed_target_temp * 0.95} MAXIMUM={bed_target_temp * 1.05}
{% endif %}
M191 S{chamber_target_temp} ; Set and wait for chamber temperature
M190 S{bed_target_temp} ; Set and wait for bed temperature
G90 ; Set absolute positioning
G1 X{start_position_x} Y{start_position_y} Z{start_position_z} F7800 ; Move to start position
G28 Z ; Home Z again for to compensate bed expansion
{% if KAMP_deactivated %}
{% if "STATIC_MESH" in printer.bed_mesh.profiles %} ; Check if the spicific STATIC_MESH exists
M118 Loading 'STATIC_MESH' instead of KAMP.
BED_MESH_PROFILE LOAD=STATIC_MESH
{% else %} ; Fallback to KAMP if STATIC_MESH not found
M118 ERROR: 'STATIC_MESH' not found! Using fallback: KAMP Adaptive Mesh.
BED_MESH_CLEAR ; Clear previous adaptive mesh
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1 ; Start adaptive meshing
{% endif %}
{% else %} ; Standard operation
{% if printer.toolhead.homed_axes|length < 3 %}
G28
{% endif %}
BED_MESH_CLEAR ; Clear previous adaptive mesh
BED_MESH_CALIBRATE PROFILE=adaptive ADAPTIVE=1 ; Start adaptive meshing
{% endif %}
PRIME_NOZZLE hotend_target_temp={hotend_target_temp}
M109 S{hotend_target_temp} ; Set and wait for hotend temperature