Error evaluating 'gcode_macro BED_MESH_CALIBRATE:gcode': UndefinedError: 'dict object' has no attribute 'polygon'

Continuing the discussion from Issue: Adaptive Mesh giving errors:

Iam now having this issue
Error evaluating ‘gcode_macro BED_MESH_CALIBRATE:gcode’: UndefinedError: ‘dict object’ has no attribute ‘polygon’

Hello @johnny !

When you opened this thread, you should have seen this:

grafik

You deleted it.

How can we help without the information that have been asked for?

2 Likes

Printer Model: Ender 3 Pro Switchwire conversion
MCU / Printer board: Bigtree Skr Mini E3 V2
Klippy Log:
klippy (1).log (973.7 KB)
My Issue When trying to print or do a Bed Mesh Calibrate I get this error and can not continue.
Error evaluating ‘gcode_macro BED_MESH_CALIBRATE:gcode’: UndefinedError: ‘dict object’ has no attribute ‘polygon’

Actually, the error lies within this giant pile of lines:

[gcode_macro BED_MESH_CALIBRATE]
rename_existing = _BED_MESH_CALIBRATE
variable_buffer = 2
gcode = 
	{% set bedMeshConfig = printer['configfile'].config["bed_mesh"] %}
	{% set bed_mesh_min = bedMeshConfig.mesh_min %}
	{% set bed_mesh_max = bedMeshConfig.mesh_max %}
	{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %}
	{% set x_min = all_points | map(attribute=0) | min | default(bed_mesh_min[0]) %}
	{% set y_min = all_points | map(attribute=1) | min | default(bed_mesh_min[1]) %}
	{% set x_max = all_points | map(attribute=0) | max | default(bed_mesh_max[0]) %}
	{% set y_max = all_points | map(attribute=1) | max | default(bed_mesh_max[1]) %}
	{% if printer["bed_mesh"].profile_name == '' %}
	{ action_respond_info("No existing bed mesh found.") }
	{% set last_area_end_x=-1 %}
	{% endif %}
	{% if printer.toolhead.homed_axes != "xyz" %}
	G28
	{% endif %}
	{% set klicky_available = printer['gcode_macro _Probe_Variables'] != null %}
	{% set probeConfig = printer['configfile'].config["probe"] %}
	{% if probeConfig %}
	{% set OffsetX = probeConfig.x_offset|default(0)|float %}
	{% set OffsetY = probeConfig.y_offset|default(0)|float %}
	{% endif %}
	{% set print_min_x = x_min|float %}
	{% set print_min_y = y_min|float %}
	{% set print_max_x = x_max|float %}
	{% set print_max_y = y_max|float %}
	{% set mesh_min_x = bed_mesh_min.split(",")[0]|float %}
	{% set mesh_min_y = bed_mesh_min.split(",")[1]|float %}
	{% set mesh_max_x = bed_mesh_max.split(",")[0]|float %}
	{% set mesh_max_y = bed_mesh_max.split(",")[1]|float %}
	{% if (print_min_x < mesh_min_x) or (print_max_x > mesh_max_x) or (print_min_y < mesh_min_y) or (print_max_y > mesh_max_y)  %}
	{% set print_min_x = mesh_min_x %}
	{% set print_min_y = mesh_min_y %}
	{% set print_max_x = mesh_max_x %}
	{% set print_max_y = mesh_max_y %}
	{% endif %}
	{% if klicky_available %}
	_CheckProbe action=query
	Attach_Probe
	{% elif euclid_available %}
	DEPLOY_PROBE
	{% endif %}
	{% if (print_min_x < print_max_x) and (print_min_y < print_max_y) %}
	{% set minimum_probe_count = 3 %}
	{% set medium_probe_count = 5 %}
	{% set probe_count = bedMeshConfig.probe_count.split(",") %}
	{% set probe_count_x = probe_count[0]|int %}
	{% if probe_count.__len__() > 1 %}
	{% set probe_count_y = probe_count[1]|int %}
	{% else %}
	{% set probe_count_y = probe_count_x|int %}
	{% endif %}
	{% set relative_reference_index = bedMeshConfig.relative_reference_index %}
	{% if print_max_x - print_min_x < (mesh_max_x - mesh_min_x) * 0.75 %}
	{% set probe_count_x = medium_probe_count %}
	{% endif %}
	{% if print_max_y - print_min_y < (mesh_max_y - mesh_min_y) * 0.75 %}
	{% set probe_count_y = medium_probe_count %}
	{% endif %}
	{% if print_max_x - print_min_x < (mesh_max_x - mesh_min_x) * 0.50 %}
	{% set probe_count_x = minimum_probe_count %}
	{% endif %}
	{% if print_max_y - print_min_y < (mesh_max_y - mesh_min_y) * 0.50 %}
	{% set probe_count_y = minimum_probe_count %}
	{% endif %}
	{% if print_min_x - buffer >= mesh_min_x %}
	{% set mesh_min_x = print_min_x - buffer %}
	{% endif %}
	{% if print_min_y - buffer >= mesh_min_y %}
	{% set mesh_min_y = print_min_y - buffer %}
	{% endif %}
	{% if print_max_x + buffer <= mesh_max_x %}
	{% set mesh_max_x = print_max_x + buffer %}
	{% endif %}
	{% if print_max_y + buffer <= mesh_max_y %}
	{% set mesh_max_y = print_max_y + buffer %}
	{% endif %}
	{ action_respond_info("mesh_min: %s,%s" % (mesh_min_x, mesh_min_y)) }
	{ action_respond_info("mesh_max: %s,%s" % (mesh_max_x, mesh_max_y)) }
	{ action_respond_info("probe_count: %s,%s" % (probe_count_x,probe_count_y)) }
	{% if printer["gcode_macro status_meshing"] != null %}
	status_meshing
	{% endif %}
	{% if relative_reference_index == 0 or relative_reference_index == null %}
	_BED_MESH_CALIBRATE mesh_min={mesh_min_x},{mesh_min_y} mesh_max={mesh_max_x},{mesh_max_y} probe_count={probe_count_x},{probe_count_y}
	{% else %}
	{% set relative_reference_index = ((probe_count_x * probe_count_y - 1) / 2)|int %}
	{ action_respond_info("relative_reference_index: %s" % relative_reference_index) }
	_BED_MESH_CALIBRATE mesh_min={mesh_min_x},{mesh_min_y} mesh_max={mesh_max_x},{mesh_max_y} probe_count={probe_count_x},{probe_count_y} relative_reference_index={relative_reference_index}
	{% endif %}
	{% else %}
	{% if printer["gcode_macro status_meshing"] != null %}
	status_meshing
	{% endif %}
	_BED_MESH_CALIBRATE
	{% endif %}
	{% if klicky_available %}
	Dock_Probe
	{% elif euclid_available %}
	STOW_PROBE
	{% endif %}
	{% if printer["gcode_macro status_ready"] != null %}
	status_ready
	{% endif %}

The author should know what they have done here.

So how do I fix it again?

Talk to whoever wrote that giant pile of lines and tell them that it’s generating an error.

You might suggest that they replace

{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %}

with

{% set all_points = printer.exclude_object.objects | selectattr('polygon', 'defined') | map(attribute='polygon') | sum(start=[]) %}
1 Like

Thank you for the advice.

Actually this is what wrote that pile of lines of course this did not get up Klipper Macro by GAB3D (gab-3d.com)dated with Klipper

Only trust a macro when you know how it works.

IMO it is a bit much to use some arbitrary macro generator and then expect the folks here to debug its questionable results :face_with_raised_eyebrow:

2 Likes