Skip to content

Instantly share code, notes, and snippets.

@ChipCE
Last active Nov 22, 2022
Embed
What would you like to do?
Klipper bed mesh on print area only macro install guide

Klipper mesh on print area only install guide

What this macro do

  • This macro will dymanic change the bed_mesh area based on the size of the printed part. The fw will only probe on the area that the part will be printed (plus mesh_area_offset value)

Setup guide

  • (1) Add the following macrro to your printer config, this will replace the default BED_MESH_CALIBRATE command.
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_BASE
; gcode parameters
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
; the clearance between print area and probe area 
variable_mesh_area_offset : 5.0
; number of sample per probe point
variable_probe_samples : 2
; minimum probe count
variable_min_probe_count : 3
; scale up the probe count, should be 1.0 ~ < variable_max_probe_count/variable_min_probe_count
variable_probe_count_scale_factor : 1.0
; enable preference index
variable_enable_reference_index : False
gcode:
    {% if params.AREA_START and params.AREA_END %}
        {% set bedMeshConfig = printer["configfile"].config["bed_mesh"] %}
        {% set safe_min_x = bedMeshConfig.mesh_min.split(",")[0]|float %}
        {% set safe_min_y = bedMeshConfig.mesh_min.split(",")[1]|float %}
        {% set safe_max_x = bedMeshConfig.mesh_max.split(",")[0]|float %}
        {% set safe_max_y = bedMeshConfig.mesh_max.split(",")[1]|float %}

        {% set area_min_x = params.AREA_START.split(",")[0]|float %}
	{% set area_min_y = params.AREA_START.split(",")[1]|float %}
	{% set area_max_x = params.AREA_END.split(",")[0]|float %}
	{% set area_max_y = params.AREA_END.split(",")[1]|float %}

	{% if bedMeshConfig.probe_count.split(",")|length == 2 %}
            {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
            {% set meshPointY = bedMeshConfig.probe_count.split(",")[1]|int %}
        {% else %}
            {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
            {% set meshPointY = bedMeshConfig.probe_count.split(",")[0]|int %}
        {% endif %}

	{% set meshMaxPointX = meshPointX %}
	{% set meshMaxPointY = meshPointY %}


        {% if (area_min_x < area_max_x) and (area_min_y < area_max_y) %}
            {% if area_min_x - mesh_area_offset >=  safe_min_x %}
                {% set area_min_x = area_min_x - mesh_area_offset %}
            {% else %}
                {% set area_min_x = safe_min_x %}
            {% endif %}

            {% if area_min_y - mesh_area_offset >=  safe_min_y %}
                {% set area_min_y = area_min_y - mesh_area_offset %}
            {% else %}
                {% set area_min_y = safe_min_y %}
            {% endif %}

            {% if area_max_x + mesh_area_offset <=  safe_max_x %}
                {% set area_max_x = area_max_x + mesh_area_offset %}
            {% else %}
                {% set area_max_x = safe_max_x %}
            {% endif %}

            {% if area_max_y + mesh_area_offset <=  safe_max_y %}
                {% set area_max_y = area_max_y + mesh_area_offset %}
            {% else %}
                {% set area_max_y = safe_max_y %}
            {% endif %}

            {% set meshPointX = (meshPointX * (area_max_x - area_min_x) / (safe_max_x - safe_min_x) * probe_count_scale_factor)|round(0)|int %}
            {% if meshPointX < min_probe_count %}
                {% set meshPointX = min_probe_count %}
            {% endif %}
	    {% if meshPointX > meshMaxPointX %}
                {% set meshPointX = meshMaxPointX %}
            {% endif %}

            {% set meshPointY = (meshPointY * (area_max_y -area_min_y ) / (safe_max_y - safe_min_y) * probe_count_scale_factor )|round(0)|int %}
            {% if meshPointY < min_probe_count %}
                {% set meshPointY = min_probe_count %}
            {% endif %}
	    {% if meshPointY > meshMaxPointY %}
                {% set meshPointY = meshMaxPointY %}
            {% endif %}

            {% set algorithm = "lagrange" %}
            {% if "algorithm" in bedMeshConfig and meshPointX >=4 and meshPointY >=4 %}
                {% set algorithm = bedMeshConfig.algorithm %}
            {% endif %}

            {% if enable_reference_index %}
                {% set referenceIndex = (meshPointX * meshPointY / 2 - 1 )|round(0)|int %}
                BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int} algorithm={algorithm} relative_reference_index={referenceIndex}
            {% else %}
                BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int} algorithm={algorithm}
            {% endif %}
        {% else %}
            BED_MESH_CALIBRATE_BASE
        {% endif %}
    {% else %}
        BED_MESH_CALIBRATE_BASE
    {% endif %}
  • (2) Go to slicer setting and replace the old bed mesh gcode the following command.

Prusa Slicer
BED_MESH_CALIBRATE AREA_START={first_layer_print_min[0]},{first_layer_print_min[1]} AREA_END={first_layer_print_max[0]},{first_layer_print_max[1]}

Ideal maker
BED_MESH_CALIBRATE AREA_START={print_pos_min_x},{print_pos_min_y} AREA_END={print_pos_max_x},{print_pos_max_y}

Cura slicer
BED_MESH_CALIBRATE AREA_START=%MINX%,%MINY% AREA_END=%MAXX%,%MAXY%

*(Cura slicer plugin) To make the macro to work in Cura slicer, you need to install the post process plugin by frankbags - In cura menu Help -> Show configuration folder. - Copy the python script from the above link in to scripts folder. - Restart Cura - In cura menu Extensions -> Post processing -> Modify G-Code and select Mesh Print Size

For user using single command START_PRINT

  • (*) If you use single command start gcode like START_PRINT BED_TEMP={material_bed_temperature_layer_0} EXTRUDER_TEMP={material_print_temperature_layer_0} .You might need to add parameter parsing to BED_MESH_CALIBRATE inside START_PRINT. This is an example, also check my macro sample
[gcode_macro START_PRINT]
variable_parameter_EXTRUDER_TEMP: 190
variable_parameter_BED_TEMP: 60
; gcode parameters for area bed mesh
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
gcode:
    # preheat, homing, etc
    BED_MESH_CALIBRATE AREA_START={params.AREA_START|default("0,0")} AREA_END={params.AREA_END|default("0,0")}
    # the rest of your start macro here

And you will need to change Slicer start gcode to this

  • Cura: START_PRINT EXTRUDER_TEMP={material_print_temperature_layer_0} BED_TEMP={material_bed_temperature_layer_0} AREA_START=%MINX%,%MINY% AREA_END=%MAXX%,%MAXY%
  • Prusa slicer: START_PRINT EXTRUDER_TEMP=[first_layer_temperature] BED_TEMP=[first_layer_bed_temperature] AREA_START={first_layer_print_min[0]},{first_layer_print_min[1]} AREA_END={first_layer_print_max[0]},{first_layer_print_max[1]}

change logs

  • 2022/07/21
    • Added force lagrange algorithm for mesh with lower than 3 points
    • Added enable_reference_index config flag
@VozzickaR
Copy link

VozzickaR commented Jun 20, 2022

Hi,
I have a problem with Heating Bed/Extruder after implementing this Macro. Can you help me with that?
After start print klipper say

 17:40:32
Error on 'M140 S': unable to parse

On slicer Cura i use Start G  code:
START_PRINT EXTRUDER_TEMP={material_print_temperature_layer_0} BED_TEMP={material_bed_temperature_layer_0} AREA_START=%MINX%,%MINY% AREA_END=%MAXX%,%MAXY%






# [gcode_macro START_PRINT]


variable_parameter_EXTRUDER_TEMP: 190
 variable_parameter_BED_TEMP: 60
 gcode parameters for area bed mesh
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
gcode:

 Start bed/EXTRUDER heating
 M140 S{BED_TEMP}
    M104 S{EXTRUDER_TEMP}
     # Use absolute coordinates
     G90
     # Reset the G-Code Z offset (adjust Z offset if needed)
     SET_GCODE_OFFSET Z=0.0
     ## Home the printer
     G28
      BED_MESH_CALIBRATE AREA_START={params.AREA_START|default("0,0")} AREA_END={params.AREA_END|default("0,0")}
    M140 S{BED_TEMP} ; set bed temp in background, do not wait
    ; report temperature
    M104 S{EXTRUDER_TEMP} ; set extruder temp
    G1 Z25 X8 F1500
    # Wait for bed to reach temperature
    M190 S{bed_temp}
    # Set and wait for nozzle to reach temperature
    M109 S{extruder_temp}
    # Reset Extruder
    G92 E0
    # Move Z Axis up
    G1 Z2.0 F3000
    # Move to start position
    G1 X8 Y20 Z0.28 F5000.0
    # Draw the first line
    G1 X8 Y200.0 Z0.28 F1500.0 E15
    # Move to side a little
    G1 X8.3 Y200.0 Z0.28 F5000.0
    # Draw the second line
    G1 X8.3 Y20 Z0.28 F1500.0 E30
    # Reset Extruder
    G92 E0
    # Move Z Axis up
    G1 Z2.0 F3000
    # Print message on LCD
`
`[Full Config](https://pastebin.com/apU3WAZK) 

Problem solved
Now i repeate adding your macro in Cfg, and its work, idk where, or what mistake i do...

@david115599
Copy link

david115599 commented Jul 7, 2022

@DerBierBaron @krpepe @selrahc13 Sorry, I haven't been able to figure out how to post the code correctly on Github. Here it is on pastebin https://pastebin.com/Y1EGXu8M

For better searchability this code linked above resolves this issue:
Internal error on command:"BED_MESH_CALIBRATE_BASE"
Once the underlying issue is corrected, use the
"FIRMWARE_RESTART" command to reset the firmware, reload the
config, and restart the host software.
Printer is shutdown

@roboduid
Copy link

roboduid commented Jul 17, 2022

I'm getting this issue on one of my prints. Can't seem to fix it. Using SuperSlicer Mosaic Edition with an Ender 3 V2 that has a hemera revo and bl touch
unknown

@lungkao
Copy link

lungkao commented Jul 19, 2022

how to for simplify3d

@todstelzer
Copy link

todstelzer commented Jul 19, 2022

@ChipCE Thanks for the answer, you're absolutetly right! Also, I had the same error as @Durahl on December 8th and I thought you might want to add a note. The problem was that I had a relative_reference_index set in my [bed_mesh] section set at 24 (for my default 7x7 grid) and it was causing an error when it was to do a grid say of 9 points. Needed to dig into the klipper.log to understand what the problem was. What I did is add the line {% set referenceIndex = (meshPointX * meshPointY / 2 - 1 )|round(0)|int %} at Line 74, and change the call for the custom bed_mesh_calibrate at line 75 for BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} relative_reference_index={referenceIndex} samples={probe_samples|int}

This could be useful for people wanting to use a relative_reference_index for their bed_mesh. Or else maybe mention to remove this parameter alltogether in [bed_mesh] section.

Thank you that was helpful. Strange that this isn´t in the doc or as separate config example available.

@ChipCE
Copy link
Author

ChipCE commented Jul 21, 2022

The problem was that I had a relative_reference_index set in my [bed_mesh] section set at 24 (for my default 7x7 grid) and it was causing an error when it was to do a grid say of 9 points. Needed to dig into the klipper.log to understand what the problem was. What I did is add the line {% set referenceIndex = (meshPointX * meshPointY / 2 - 1 )|round(0)|int %} at Line 74, and change the call for the custom bed_mesh_calibrate at line 75 for BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} relative_reference_index={referenceIndex} samples={probe_samples|int}

Thank you!
I updated the script based on your suggestion, relative_reference_index is now can be enable with variable_enable_reference_index : True<,code>

@ChipCE
Copy link
Author

ChipCE commented Jul 21, 2022

I'm getting this issue on one of my prints. Can't seem to fix it. Using SuperSlicer Mosaic Edition with an Ender 3 V2 that has a hemera revo and bl touch unknown

bicubic need atleast 4x4 mesh. I updated the macro, it will now auto switch to lagrange algorithm if the mesh point are lower than 4

@roboduid
Copy link

roboduid commented Jul 24, 2022

I'm getting this issue on one of my prints. Can't seem to fix it. Using SuperSlicer Mosaic Edition with an Ender 3 V2 that has a hemera revo and bl touch unknown

bicubic need atleast 4x4 mesh. I updated the macro, it will now auto switch to lagrange algorithm if the mesh point are lower than 4

I'm now getting that It wants to use Lagrange, but can't
image

@ChipCE
Copy link
Author

ChipCE commented Jul 25, 2022

I'm getting this issue on one of my prints. Can't seem to fix it. Using SuperSlicer Mosaic Edition with an Ender 3 V2 that has a hemera revo and bl touch unknown

bicubic need atleast 4x4 mesh. I updated the macro, it will now auto switch to lagrange algorithm if the mesh point are lower than 4

I'm now getting that It wants to use Lagrange, but can't image

I will try to fix that later, for now please change variable_min_probe_count : 3 to variable_min_probe_count : 4

@bjj
Copy link

bjj commented Aug 1, 2022

This is an amazing macro! Can I recommend expanding the (8 space) tabs that are used on a few lines of the macro? It would make cutting and pasting easier.

@kubark42
Copy link

kubark42 commented Sep 20, 2022

@panik988 @Lecso11, et al:
There are two things I had to do to get this to work with Klicky.

  1. Place the below into a file called bed_mesh_print_area.cfg.
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_BASE
; gcode parameters
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
; the clearance between print area and probe area 
variable_mesh_area_offset : 5.0
; number of sample per probe point
variable_probe_samples : 2
; minimum probe count
variable_min_probe_count : 3
; scale up the probe count, should be 1.0 ~ < variable_max_probe_count/variable_min_probe_count
variable_probe_count_scale_factor : 1.0
; enable preference index
variable_enable_reference_index : False

variable_mesh_delta : 25                   ## distance between points
variable_x_mesh_max : 7                    ## max points on x-axis
variable_y_mesh_max : 7                    ## max points on y-axis

gcode:

    _CheckProbe action=query
	G90
    Attach_Probe

	{% if params.AREA_START and params.AREA_END %}
	## get [bed_mesh] config parameters
		{% set bedMeshConfig = printer["configfile"].config["bed_mesh"] %}
		{% set safe_min_x = bedMeshConfig.mesh_min.split(",")[0]|float %}
		{% set safe_min_y = bedMeshConfig.mesh_min.split(",")[1]|float %}
		{% set safe_max_x = bedMeshConfig.mesh_max.split(",")[0]|float %}
		{% set safe_max_y = bedMeshConfig.mesh_max.split(",")[1]|float %}
	## get print area min/max from slicer gcode
		{% set area_min_x = params.AREA_START.split(",")[0]|float %}
		{% set area_min_y = params.AREA_START.split(",")[1]|float %}
		{% set area_max_x = params.AREA_END.split(",")[0]|float %}
		{% set area_max_y = params.AREA_END.split(",")[1]|float %}
	## set probing area
		{% if area_min_x - mesh_area_offset >=  safe_min_x %}
			{% set area_min_x = area_min_x - mesh_area_offset %}
			{% else %}
			{% set area_min_x = safe_min_x %}
		{% endif %}
		{% if area_min_y - mesh_area_offset >=  safe_min_y %}
			{% set area_min_y = area_min_y - mesh_area_offset %}
			{% else %}
			{% set area_min_y = safe_min_y %}
		{% endif %}
		{% if area_max_x + mesh_area_offset <=  safe_max_x %}
			{% set area_max_x = area_max_x + mesh_area_offset %}
			{% else %}
			{% set area_max_x = safe_max_x %}
		{% endif %}
		{% if area_max_y + mesh_area_offset <=  safe_max_y %}
			{% set area_max_y = area_max_y + mesh_area_offset %}
			{% else %}
			{% set area_max_y = safe_max_y %}
		{% endif %}
	## set probe counts
		{% set meshPointX = ((area_max_x - area_min_x) / mesh_delta + 1)|round(0)|int %}
		{% if meshPointX < 3 %}
			{% set meshPointX = 3 %}
			{% elif meshPointX > x_mesh_max %}
			{% set meshPointX = x_mesh_max %}
		{% endif %}
		{% set meshPointY = ((area_max_y - area_min_y) / mesh_delta + 1)|round(0)|int %}
		{% if meshPointY < 3 %}
			{% set meshPointY = 3 %}
			{% elif meshPointY > y_mesh_max %}
			{% set meshPointY = y_mesh_max %}
		{% endif %}
	## check for invalid mesh
		{% if meshPointX > 5 %}
			{% if meshPointY == 3 %}  # 7x3 mesh invalid for bicubic
			{% set meshPointY = 5 %}  # set 7x5 mesh
			{% endif %}
		{% endif %}
		{% if meshPointY > 5 %}
			{% if meshPointX == 3 %}  # 3x7 mesh invalid for bicubic
			{% set meshPointX = 5 %}  # set 5x7 mesh
			{% endif %}
		{% endif %}
	## set new reference index point
		{% set referenceIndex = (meshPointX * meshPointY / 2 - 1 )|round(0)|int %}
	## send bed mesh parameters
		M117 probe_count={meshPointX},{meshPointY}
		BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} relative_reference_index={referenceIndex} 
	{% else %}
	BED_MESH_CALIBRATE_BASE
	{% endif %}

    Dock_Probe
  1. Place the below into klicky-probe.cfg.
[include ./bed_mesh_print_area.cfg]             # Bounding box for mesh https://gist.github.com/ChipCE/95fdbd3c2f3a064397f9610f915f7d02?permalink_comment_id=4119897#gistcomment-4119897

You can test with, e.g., BED_MESH_CALIBRATE AREA_START=100,100 AREA_END=200,200

@chainbreaker2012
Copy link

chainbreaker2012 commented Sep 21, 2022

Quick question reguarding the relative_reference_index would thee be a way to do a macro for taking mesh lowest point and using that as the relative reference index? Or is that already taken care of in this?

@locki-cz
Copy link

locki-cz commented Sep 21, 2022

Is possible do it without changes in slicer?

@kubark42
Copy link

kubark42 commented Sep 21, 2022

@locki-cz you can test manually with BED_MESH_CALIBRATE AREA_START=50,50 AREA_END=100,100. This will do a mesh across a square bounded by (50,50) and (100,100) You'll have to set the bounding box yourself, though, since it's not coming from the slicer.

@locki-cz
Copy link

locki-cz commented Oct 5, 2022

I followed this manual but i am not able figureou what is wrong :(

21:02:24 Klipper state: Disconnect
21:02:24 FIRMWARE_RESTART
21:02:08 Internal error on command:"PRINT_START"
21:02:08 Internal error on command:"BED_MESH_CALIBRATE"
21:02:08 Internal error on command:"BED_MESH_CALIBRATE_BASE"

image

@dnahas
Copy link

dnahas commented Oct 11, 2022

To enforce an odd number of probe points, I added the following, BEFORE the {% set algorithm = "lagrange" %} line. **This (lazy) placement can increase an even max points variable.

{% if meshPointX is divisibleby 2 %}
     {% set meshPointX = meshPointX + 1 %}
{% endif %}
{% if meshPointY is divisibleby 2 %}
     {% set meshPointY = meshPointY + 1 %}
{% endif %}

@ChipCE Thank you for you effort!!

@datapaganism
Copy link

datapaganism commented Oct 21, 2022

Is there any possible way to increase the object area and add a purge line?

@ChipCE
Copy link
Author

ChipCE commented Oct 21, 2022

@datapaganism Yes, its possible but

  • this macro is a override of the original command and it should do just that
  • Each machine have it's purge line position, length and direction. It's hard to make one to work for all.

A simple hack that cam make it work on your machine: save area_min_x, area_min_y, area_max_x, area_max_y to some where(with saved variable or set gcode variable value) and use that as preference for your purge line gcode/macro

@ChipCE
Copy link
Author

ChipCE commented Oct 21, 2022

@dnahas Thank you!
My small machine actually have max possible probe count 6x6 so i might want to keep the even probe count. I have ideal to fix all the algorithm and probe count problem. I will try to move my lazy ass and fix that in the next few days.

@dnahas
Copy link

dnahas commented Oct 22, 2022

Is there any possible way to increase the object area and add a purge line? @datapaganism

For RatRig RatOS I changed the following PRIME_LINE macro lines (I didnt see the need to save it).

From:

  G1 X{printer.toolhead.axis_minimum.x + 5} Y{printer.toolhead.axis_minimum.y + 10} F{speed}
  G1 Y{printer.toolhead.axis_minimum.y + 80} E16 F1200
  G1 Y{printer.toolhead.axis_minimum.y + 100} F{speed}

To:

  G1 X{printer.bed_mesh.mesh_min[0]|float} Y{printer.bed_mesh.mesh_min[1]|float} F{speed}
  G1 Y{printer.bed_mesh.mesh_min[1]|float + 80} E16 F1200
  G1 Y{printer.bed_mesh.mesh_min[1]|float + 100} F{speed}

*This is my lazy code that does not provide any check for out side of safe area.

Also see
printer.bed_mesh.profiles.XXXXXX.mesh_params.min_y
printer.configfile.save_config_pending_items['XXXXXX'].min_y

@pjaxed
Copy link

pjaxed commented Oct 29, 2022

Thank you @ChipCE and all contributors. I now have this working with my Klicky probe setup. One issue left for me to work though is the Z Offset which is now off. Any pointers where to look?

@5P4P
Copy link

5P4P commented Oct 29, 2022

Thank you @ChipCE and all contributors. I now have this working with my Klicky probe setup. One issue left for me to work though is the Z Offset which is now off. Any pointers where to look?

This works great on my Voron 2.4r2 https://github.com/protoloft/klipper_z_calibration

@pjaxed
Copy link

pjaxed commented Oct 29, 2022

@xdased14x
Copy link

xdased14x commented Nov 1, 2022

@panik988 @Lecso11, et al: There are two things I had to do to get this to work with Klicky.

  1. Place the below into a file called bed_mesh_print_area.cfg.
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_BASE
; gcode parameters
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
; the clearance between print area and probe area 
variable_mesh_area_offset : 5.0
; number of sample per probe point
variable_probe_samples : 2
; minimum probe count
variable_min_probe_count : 3
; scale up the probe count, should be 1.0 ~ < variable_max_probe_count/variable_min_probe_count
variable_probe_count_scale_factor : 1.0
; enable preference index
variable_enable_reference_index : False

variable_mesh_delta : 25                   ## distance between points
variable_x_mesh_max : 7                    ## max points on x-axis
variable_y_mesh_max : 7                    ## max points on y-axis

gcode:

    _CheckProbe action=query
	G90
    Attach_Probe

	{% if params.AREA_START and params.AREA_END %}
	## get [bed_mesh] config parameters
		{% set bedMeshConfig = printer["configfile"].config["bed_mesh"] %}
		{% set safe_min_x = bedMeshConfig.mesh_min.split(",")[0]|float %}
		{% set safe_min_y = bedMeshConfig.mesh_min.split(",")[1]|float %}
		{% set safe_max_x = bedMeshConfig.mesh_max.split(",")[0]|float %}
		{% set safe_max_y = bedMeshConfig.mesh_max.split(",")[1]|float %}
	## get print area min/max from slicer gcode
		{% set area_min_x = params.AREA_START.split(",")[0]|float %}
		{% set area_min_y = params.AREA_START.split(",")[1]|float %}
		{% set area_max_x = params.AREA_END.split(",")[0]|float %}
		{% set area_max_y = params.AREA_END.split(",")[1]|float %}
	## set probing area
		{% if area_min_x - mesh_area_offset >=  safe_min_x %}
			{% set area_min_x = area_min_x - mesh_area_offset %}
			{% else %}
			{% set area_min_x = safe_min_x %}
		{% endif %}
		{% if area_min_y - mesh_area_offset >=  safe_min_y %}
			{% set area_min_y = area_min_y - mesh_area_offset %}
			{% else %}
			{% set area_min_y = safe_min_y %}
		{% endif %}
		{% if area_max_x + mesh_area_offset <=  safe_max_x %}
			{% set area_max_x = area_max_x + mesh_area_offset %}
			{% else %}
			{% set area_max_x = safe_max_x %}
		{% endif %}
		{% if area_max_y + mesh_area_offset <=  safe_max_y %}
			{% set area_max_y = area_max_y + mesh_area_offset %}
			{% else %}
			{% set area_max_y = safe_max_y %}
		{% endif %}
	## set probe counts
		{% set meshPointX = ((area_max_x - area_min_x) / mesh_delta + 1)|round(0)|int %}
		{% if meshPointX < 3 %}
			{% set meshPointX = 3 %}
			{% elif meshPointX > x_mesh_max %}
			{% set meshPointX = x_mesh_max %}
		{% endif %}
		{% set meshPointY = ((area_max_y - area_min_y) / mesh_delta + 1)|round(0)|int %}
		{% if meshPointY < 3 %}
			{% set meshPointY = 3 %}
			{% elif meshPointY > y_mesh_max %}
			{% set meshPointY = y_mesh_max %}
		{% endif %}
	## check for invalid mesh
		{% if meshPointX > 5 %}
			{% if meshPointY == 3 %}  # 7x3 mesh invalid for bicubic
			{% set meshPointY = 5 %}  # set 7x5 mesh
			{% endif %}
		{% endif %}
		{% if meshPointY > 5 %}
			{% if meshPointX == 3 %}  # 3x7 mesh invalid for bicubic
			{% set meshPointX = 5 %}  # set 5x7 mesh
			{% endif %}
		{% endif %}
	## set new reference index point
		{% set referenceIndex = (meshPointX * meshPointY / 2 - 1 )|round(0)|int %}
	## send bed mesh parameters
		M117 probe_count={meshPointX},{meshPointY}
		BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} relative_reference_index={referenceIndex} 
	{% else %}
	BED_MESH_CALIBRATE_BASE
	{% endif %}

    Dock_Probe
  1. Place the below into klicky-probe.cfg.
[include ./bed_mesh_print_area.cfg]             # Bounding box for mesh https://gist.github.com/ChipCE/95fdbd3c2f3a064397f9610f915f7d02?permalink_comment_id=4119897#gistcomment-4119897

You can test with, e.g., BED_MESH_CALIBRATE AREA_START=100,100 AREA_END=200,200

tried this and i get a full bed mesh every time i run a test print. the part i'm using is small and i move it around the bed
i committed out the the klicky bed mesh cfg,not sure what i'm doing wrong

@pjaxed
Copy link

pjaxed commented Nov 3, 2022

Thank you for feedback. Issue was with the code generated by my slicer. All is working as it should.

@C0NN0R92
Copy link

C0NN0R92 commented Nov 5, 2022

i keep getting Error evaluating 'gcode_macro BED_MESH_CALIBRATE:gcode': jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'bed_mesh' can anyone help me

@ChipCE
Copy link
Author

ChipCE commented Nov 5, 2022

i keep getting Error evaluating 'gcode_macro BED_MESH_CALIBRATE:gcode': jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'bed_mesh' can anyone help me

seem like "bed_mesh" is missing in your original config

@ga-rr-is-on
Copy link

ga-rr-is-on commented Nov 17, 2022

To get this to work on IdeaMaker using single Start_Print
(including temp parameters to help those that are new to using Klipper macros and parameters within the Slicer G-Code). If you can copy and paste, you don't need to modify anything.
Copy and paste the BED_MESH_CALIBRATE macro as per instructions above to your printer.cfg file.
If you have a START_PRINT macro already in you printer.cfg file, comment out that section and paste the code below above the code you just commented out. If not, just paste this under the BED_MESH_CALIBRATE macro. Indentation is important.

[gcode_macro START_PRINT]
gcode:
    {% set BED_TEMP = params.BED_TEMP|default(60)|float %} # Setup bed temp parameter and give it a default value of 60
    {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(210)|float %} # Setup extruder temp parameter and give it a default value of 210
    {% set AREA_START = params.AREA_START|default("75,75") %} # Setup start coordinates for the mesh and give it a default of 75,75
    {% set AREA_END = params.AREA_END|default("125,125") %} # Setup end coordinates for the mesh and give it a default of 125,125
    #The original default values for the Start and End coordinates were both 0,0, which either takes the measured value at 0,0 and uses that value everywhere, or does nothing, i forget
    #75,75 and 125,125 will at least probe a small area close to the middle depending on your size bed. Adjust however you want. 
    M140 S{BED_TEMP} # Start bed heating using the declared or default value
    G28 # Home the printer while we wait on the bed to heat up
    M190 S{BED_TEMP} # Wait for bed to reach temperature
    BED_MESH_CALIBRATE AREA_START={params.AREA_START} AREA_END={params.AREA_END} # Create the mesh
    G90 # Use absolute coordinates
    G1 X1 Y1 F5000; Move to the front left corner
    SET_GCODE_OFFSET Z=0.0 # Reset the G-Code Z offset (adjust Z offset if needed)
    G1 Z5 F3000 # Move the nozzle near the bed    
    G1 Z0.15 F300 # Move the nozzle very close to the bed
    M109 S{EXTRUDER_TEMP} # Set and wait for nozzle to reach temperature

Uncomment any additional lines that you commented out of the existing START_PRINT macro that you want to include and each line is commented so you understand exactly what it is doing.

Leave anything commented out that you do not know what it is doing until you can add your own comments. Additional commands are useful, but not necessary.

Add this to your Start GCode setting in IdeaMaker:

START_PRINT EXTRUDER_TEMP={temperature_extruder1} BED_TEMP={temperature_heatbed} AREA_START={print_pos_min_x},{print_pos_min_y} AREA_END={print_pos_max_x},{print_pos_max_y}

@olivierD-FR
Copy link

olivierD-FR commented Nov 19, 2022

Hello, anyone know how I can fix this problem. I receive this error not on every gcode file?

image

@olivierD-FR
Copy link

olivierD-FR commented Nov 19, 2022

Hello, anyone know how I can fix this problem. I receive this error not on every gcode file?

image

SOLVED: I was not passing the zone to test in the slicer (forgot to update all my printers config in Prusa Slicer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment