-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmacros_plates.cfg
150 lines (137 loc) · 7.57 KB
/
macros_plates.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
### Copied from zellenralex
### See about how this would work in conjunction with auto-z-calibration from Klicky
#####################################################################
# Get offset_z and name for own usage
#####################################################################
# {% set offset = printer.save_variables.variables.plates.array[printer.save_variables.variables.plates.index].offset %}
# {% set name = printer.save_variables.variables.plates.array[printer.save_variables.variables.plates.index].name %}
#
#####################################################################
#####################################################################
# Macro for the print_start gcode section of your slicer
# or your print start macro
#####################################################################
# _SET_PLATE_OFFSET [MOVE=0|1] : Set the z offset
# Set the offset of the active flexplate as an Z_ADJUST offset. MOVE=0 (default)
# will add the offset with the next z move, MOVE=1 imitate change the z offset.
#####################################################################
[gcode_macro _SET_PLATE_OFFSET]
description: Helper: Apply the z-offset of the active flexplate.
gcode:
{% if not printer.save_variables.variables.plates %}
{action_respond_info("FLEXPLATE: No plate array defined. Aborted.")}
{% else %}
{% set plates = printer.save_variables.variables.plates %}
{% set out = ["GCode Offset for Z applied from:"] %}
#Removed because I think Tap eliminates this?
#{% set _dummy = out.append("Z_CALIBRATE: %.3fmm" % printer.z_calibration.last_z_offset) %}
{% set _dummy = out.append("Plate %s offset added: %.3fmm" % (plates.array[plates.index].name,plates.array[plates.index].offset)) %}
SET_GCODE_OFFSET Z_ADJUST={plates.array[plates.index].offset} MOVE={params.MOVE|default(0)}
#{% set _dummy = out.append("Total Offset: %.3fmm" % printer.gcode_move.homing_origin.z) %}
{action_respond_info(out|join("\n"))}
{% endif %}
[gcode_macro LIST_PLATES]
description: List all flexplates.
gcode:
{% if not printer.save_variables.variables.plates %}
RESPOND TYPE=error MSG="FLEXPLATE: No plate array defined. Aborted."
{% else %}
{% set plates = printer.save_variables.variables.plates %}
{% set out = ["FLEXPLATE: Defined plates."] %}
{% for elem in range(plates.array|length) %}
{% set _dummy = out.append("INDEX: %d -> %s -> offset: %.3fmm" % (elem, plates.array[elem].name, plates.array[elem].offset)) %}
{% endfor %}
{% set _dummy = out.append("\n Active Plate: %s" % plates.array[plates.index].name) %}
{action_respond_info(out|join("\n"))}
{% endif %}
[gcode_macro SET_PLATE]
description: Set active flex plate. Usage: SET_PLATE INDEX=index
gcode:
{% if not printer.save_variables.variables.plates %}
RESPOND TYPE=error MSG="FLEXPLATE: No plate array defined. Aborted."
{% else %}
{% set plates = printer.save_variables.variables.plates %}
{% if 'INDEX' not in params|upper %}
RESPOND TYPE=error MSG="FLEXPLATE: No INDEX defined, use SET_PLATE INDEX=index. Aborted."
{% elif params.INDEX|int < 0 or params.INDEX|int >= plates.array|length %}
{% set _out="FLEXPLATE: Index out of range [0..%d]. Aborted." % (plates.array|length-1) %}
RESPOND TYPE=error MSG="{_out}"
{% else %}
{% set _dummy = plates.update({'index' : params.INDEX|int}) %}
SAVE_VARIABLE VARIABLE=plates VALUE="{plates}"
{% set _out="Plate: %s" % (plates.array[plates.index].name) %}
RESPOND TYPE=command MSG="{_out}"
{% set _out="FLEXPLATE: Set plate: %s with offset: %.3fmm" % (plates.array[plates.index].name,plates.array[plates.index].offset) %}
RESPOND TYPE=command MSG="{_out}"
UPDATE_DELAYED_GCODE ID=_CLEAR_DISPLAY DURATION=10
{% endif %}
{% endif %}
[gcode_macro ADD_PLATE]
description: Add a flexplate to the list. Usage: ADD_PLATE NAME=name OFFSET=offset
gcode:
{% set name = params.NAME|default('New')|string %}
{% set offset = params.OFFSET|default(0.0)|float|round(3) %}
{% if not printer.save_variables.variables.plates %}
{% set _out="FLEXPLATE: Initialize plate array. Add plate: %s with offset: %.3fmm at INDEX: 0" % (name,offset) %}
RESPOND TYPE=command MSG="{_out}"
{% set plates = {'array': [{'name': name, 'offset': offset}], 'index': 0} %}
{% else %}
{% set plates = printer.save_variables.variables.plates %}
{% set _out="FLEXPLATE: Add plate: %s with offset: %.3fmm at INDEX: %d" % (name,offset,plates.array|length) %}
RESPOND TYPE=command MSG="{_out}"
{% set _dummy = plates.array.append({'name': name, 'offset': offset}) %}
{% endif %}
SAVE_VARIABLE VARIABLE=plates VALUE="{plates}"
[gcode_macro REMOVE_PLATE]
description: Remove a flexplate from the list. Usage: REMOVE_PLATE INDEX=index
gcode:
{% if not printer.save_variables.variables.plates %}
RESPOND TYPE=error MSG="FLEXPLATE: No plate array defined. Aborted."
{% else %}
{% set plates = printer.save_variables.variables.plates %}
{% if 'INDEX' not in params|upper %}
RESPOND TYPE=error MSG="FLEXPLATE: No INDEX defined, use REMOVE_PLAE INDEX=index. Aborted."
{% elif plates.array|length == 1 or params.INDEX|int == plates.index %}
RESPOND TYPE=error MSG="FLEXPLATE: Last or active plate cannot be removed. Aborted."
{% elif params.INDEX|int < 0 or params.INDEX|int >= plates.array|length %}
{% set _out="FLEXPLATE: Index out of range[0..%d]. Aborted." % (plates.array|length-1) %}
RESPOND TYPE=error MSG="{_out}"
{% else %}
{% set _out="FLEXPLATE: Remove plate with INDEX %d from list " % (params.INDEX|int) %}
RESPOND TYPE=command MSG="{_out}"
{% set _dummy = plates.array.pop(params.INDEX|int) %}
SAVE_VARIABLE VARIABLE=plates VALUE="{plates}"
{% endif %}
{% endif %}
# Not working, revisit later
# [gcode_macro CHANGE_PLATE_VALUE]
# description: Change name or offset of a flexplate in the list. Usage: CHANGE_PLATE_VALUE INDEX=index [NAME=name] [OFFSET=offset]
# gcode:
# {% if not printer.save_variables.variables.plates %}
# RESPOND TYPE=error MSG="FLEXPLATE: No plate array defined. Aborted."
# {% else %}
# {% set plates = printer.save_variables.variables.plates %}
# {% set index = params.INDEX|default(plates.index)|int %}
# {% if params.INDEX|int < 0 or params.INDEX|int >= plates.array|length %}
# {% set _out="FLEXPLATE: Index out of range[0..%d]. Aborted." % (plates.array|length-1) %}
# RESPOND TYPE=error MSG="{_out}"
# {% else %}
# {% set change_txt = [] %}
# {% if 'NAME' in params|upper %}
# {% set _dummy = change_txt.append("name to %s" % params.NAME|string) %}
# {% set _dummy = plates.array[index.update({'name': params.NAME|string})] %}
# {% endif %}
# {% if 'OFFSET' in params|upper %}
# {% set _dummy = change_txt.append("offset to %.3fmm" % params.OFFSET|float|round(3)) %}
# {% set _dummy = plate.array[index].update({'offset': params.OFFSET|float|round(3)}) %}
# {% endif %}
# {% if change_txt|length >0 %}
# {% set _out="FLEXPLATE: Changed %s at plate with INDEX %d" % (cnage_txt|join(" and "),index) %}
# RESPOND TYPE=command MSG="{_out}"
# SAVE_VARIABLE VARIABLE=plates VALUE="{plates}"
# {% else %}
# {% set _out="FLEXPLATES: Nothing changed at plate with INDEX %d" % index %}
# RESPOND TYPE=command MSG="{_out}"
# {% endif %}
# {% endif %}
# {% endif %}