From 116012740922ccd8a95521b82957eaa3dc3a06d2 Mon Sep 17 00:00:00 2001 From: victornpb <3372598+victornpb@users.noreply.github.com> Date: Sat, 19 Nov 2022 03:49:15 -0300 Subject: [PATCH 1/5] added UI fields --- .../scripts/FilamentChange.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/plugins/PostProcessingPlugin/scripts/FilamentChange.py b/plugins/PostProcessingPlugin/scripts/FilamentChange.py index ff62e1949c..f61a9627e1 100644 --- a/plugins/PostProcessingPlugin/scripts/FilamentChange.py +++ b/plugins/PostProcessingPlugin/scripts/FilamentChange.py @@ -113,6 +113,38 @@ class FilamentChange(Script): }, "default_value": "RepRap (Marlin/Sprinter)", "enabled": "false" + }, + "enable_before_macro": + { + "label": "Enable macro Before filament change", + "description": "Use this to insert a custom G-code macro before the filament change happens", + "type": "bool", + "default_value": false + }, + "before_macro": + { + "label": "G-code Before", + "description": "Any custom G-code to run before the filament change happens, for example, M300 S1000 P10000 for a long beep.", + "unit": "", + "type": "str", + "default_value": "M300 S1000 P10000", + "enabled": "enable_before_macro" + }, + "enable_after_macro": + { + "label": "Enable macro After filament change", + "description": "Use this to insert a custom G-code macro after the filament change", + "type": "bool", + "default_value": false + }, + "after_macro": + { + "label": "G-code After", + "description": "Any custom G-code to run after the filament has been changed right before continuing the print, for example, you can add a sequence to purge filament and wipe the nozzle.", + "unit": "", + "type": "str", + "default_value": "M300 S440 P500", + "enabled": "enable_after_macro" } } }""" From ac16659829eeecccb8ce734bb353dcf4a4f630b6 Mon Sep 17 00:00:00 2001 From: victornpb <3372598+victornpb@users.noreply.github.com> Date: Sat, 19 Nov 2022 03:53:53 -0300 Subject: [PATCH 2/5] support custom gcode macro before and after filament change --- .../scripts/FilamentChange.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/PostProcessingPlugin/scripts/FilamentChange.py b/plugins/PostProcessingPlugin/scripts/FilamentChange.py index f61a9627e1..415154da29 100644 --- a/plugins/PostProcessingPlugin/scripts/FilamentChange.py +++ b/plugins/PostProcessingPlugin/scripts/FilamentChange.py @@ -173,8 +173,18 @@ class FilamentChange(Script): y_pos = self.getSettingValueByKey("y_position") z_pos = self.getSettingValueByKey("z_position") firmware_config = self.getSettingValueByKey("firmware_config") + enable_before_macro = self.getSettingValueByKey("enable_before_macro") + before_macro = self.getSettingValueByKey("before_macro") + enable_after_macro = self.getSettingValueByKey("enable_after_macro") + after_macro = self.getSettingValueByKey("after_macro") - color_change = "M600" + + color_change = ";BEGIN FilamentChange plugin" + + if enable_before_macro: + color_change = color_change + "\n" + before_macro + + color_change = color_change + "\n" + "M600" if not firmware_config: if initial_retract is not None and initial_retract > 0.: @@ -195,7 +205,10 @@ class FilamentChange(Script): if z_pos is not None and z_pos > 0.: color_change = color_change + (" Z%.2f" % z_pos) - color_change = color_change + " ; Generated by FilamentChange plugin\n" + if enable_after_macro: + color_change = color_change + "\n" + after_macro + + color_change = color_change + "\n;END FilamentChange plugin\n" layer_targets = layer_nums.split(",") if len(layer_targets) > 0: From 4459ecb5d73aa1e34bee411a0552e71eb9ffa782 Mon Sep 17 00:00:00 2001 From: victornpb <3372598+victornpb@users.noreply.github.com> Date: Sat, 19 Nov 2022 03:56:20 -0300 Subject: [PATCH 3/5] Added "enable" checkbox consistent with changeAtZ.py. So you don't have to reconfigure it every time --- .../scripts/FilamentChange.py | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/plugins/PostProcessingPlugin/scripts/FilamentChange.py b/plugins/PostProcessingPlugin/scripts/FilamentChange.py index 415154da29..9155edf61f 100644 --- a/plugins/PostProcessingPlugin/scripts/FilamentChange.py +++ b/plugins/PostProcessingPlugin/scripts/FilamentChange.py @@ -24,20 +24,29 @@ class FilamentChange(Script): "version": 2, "settings": { + "enabled": + { + "label": "Enable", + "description": "Uncheck to temporarily disable this feature.", + "type": "bool", + "default_value": true + }, "layer_number": { "label": "Layer", "description": "At what layer should color change occur. This will be before the layer starts printing. Specify multiple color changes with a comma.", "unit": "", "type": "str", - "default_value": "1" + "default_value": "1", + "enabled": "enabled" }, "firmware_config": { "label": "Use Firmware Configuration", "description": "Use the settings in your firmware, or customise the parameters of the filament change here.", "type": "bool", - "default_value": false + "default_value": false, + "enabled": "enabled" }, "initial_retract": { @@ -46,7 +55,7 @@ class FilamentChange(Script): "unit": "mm", "type": "float", "default_value": 30.0, - "enabled": "not firmware_config" + "enabled": "enabled and not firmware_config" }, "later_retract": { @@ -55,7 +64,7 @@ class FilamentChange(Script): "unit": "mm", "type": "float", "default_value": 300.0, - "enabled": "not firmware_config" + "enabled": "enabled and not firmware_config" }, "x_position": { @@ -64,7 +73,7 @@ class FilamentChange(Script): "unit": "mm", "type": "float", "default_value": 0, - "enabled": "not firmware_config" + "enabled": "enabled and not firmware_config" }, "y_position": { @@ -73,7 +82,7 @@ class FilamentChange(Script): "unit": "mm", "type": "float", "default_value": 0, - "enabled": "not firmware_config" + "enabled": "enabled and not firmware_config" }, "z_position": { @@ -82,7 +91,8 @@ class FilamentChange(Script): "unit": "mm", "type": "float", "default_value": 0, - "minimum_value": 0 + "minimum_value": 0, + "enabled": "enabled" }, "retract_method": { @@ -92,7 +102,7 @@ class FilamentChange(Script): "options": {"U": "Marlin (M600 U)", "L": "Reprap (M600 L)"}, "default_value": "U", "value": "\\\"L\\\" if machine_gcode_flavor==\\\"RepRap (RepRap)\\\" else \\\"U\\\"", - "enabled": "not firmware_config" + "enabled": "enabled and not firmware_config" }, "machine_gcode_flavor": { @@ -119,7 +129,8 @@ class FilamentChange(Script): "label": "Enable macro Before filament change", "description": "Use this to insert a custom G-code macro before the filament change happens", "type": "bool", - "default_value": false + "default_value": false, + "enabled": "enabled" }, "before_macro": { @@ -128,14 +139,15 @@ class FilamentChange(Script): "unit": "", "type": "str", "default_value": "M300 S1000 P10000", - "enabled": "enable_before_macro" + "enabled": "enabled and enable_before_macro" }, "enable_after_macro": { "label": "Enable macro After filament change", "description": "Use this to insert a custom G-code macro after the filament change", "type": "bool", - "default_value": false + "default_value": false, + "enabled": "enabled" }, "after_macro": { @@ -144,7 +156,7 @@ class FilamentChange(Script): "unit": "", "type": "str", "default_value": "M300 S440 P500", - "enabled": "enable_after_macro" + "enabled": "enabled and enable_after_macro" } } }""" @@ -166,6 +178,7 @@ class FilamentChange(Script): :param data: A list of layers of g-code. :return: A similar list, with filament change commands inserted. """ + enabled = self.getSettingValueByKey("enabled") layer_nums = self.getSettingValueByKey("layer_number") initial_retract = self.getSettingValueByKey("initial_retract") later_retract = self.getSettingValueByKey("later_retract") @@ -178,6 +191,8 @@ class FilamentChange(Script): enable_after_macro = self.getSettingValueByKey("enable_after_macro") after_macro = self.getSettingValueByKey("after_macro") + if not enabled: + return data color_change = ";BEGIN FilamentChange plugin" From 337ce4caa1098ce6ef47baa9e40d75274ed40e1e Mon Sep 17 00:00:00 2001 From: victornpb <3372598+victornpb@users.noreply.github.com> Date: Sat, 19 Nov 2022 04:06:26 -0300 Subject: [PATCH 4/5] shortened label --- plugins/PostProcessingPlugin/scripts/FilamentChange.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/PostProcessingPlugin/scripts/FilamentChange.py b/plugins/PostProcessingPlugin/scripts/FilamentChange.py index 9155edf61f..fc09a267f9 100644 --- a/plugins/PostProcessingPlugin/scripts/FilamentChange.py +++ b/plugins/PostProcessingPlugin/scripts/FilamentChange.py @@ -126,7 +126,7 @@ class FilamentChange(Script): }, "enable_before_macro": { - "label": "Enable macro Before filament change", + "label": "Enable G-code Before", "description": "Use this to insert a custom G-code macro before the filament change happens", "type": "bool", "default_value": false, @@ -143,7 +143,7 @@ class FilamentChange(Script): }, "enable_after_macro": { - "label": "Enable macro After filament change", + "label": "Enable G-code After", "description": "Use this to insert a custom G-code macro after the filament change", "type": "bool", "default_value": false, From 51a6afb58f1e8322f1ab5d17557c3078e1801f8c Mon Sep 17 00:00:00 2001 From: Victor <3372598+victornpb@users.noreply.github.com> Date: Mon, 19 Dec 2022 14:42:19 -0300 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Casper Lamboo --- plugins/PostProcessingPlugin/scripts/FilamentChange.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/PostProcessingPlugin/scripts/FilamentChange.py b/plugins/PostProcessingPlugin/scripts/FilamentChange.py index fc09a267f9..ef85d5ae36 100644 --- a/plugins/PostProcessingPlugin/scripts/FilamentChange.py +++ b/plugins/PostProcessingPlugin/scripts/FilamentChange.py @@ -194,12 +194,12 @@ class FilamentChange(Script): if not enabled: return data - color_change = ";BEGIN FilamentChange plugin" + color_change = ";BEGIN FilamentChange plugin\n" if enable_before_macro: - color_change = color_change + "\n" + before_macro + color_change = color_change + before_macro + "\n" - color_change = color_change + "\n" + "M600" + color_change = color_change + "M600\n" if not firmware_config: if initial_retract is not None and initial_retract > 0.: @@ -221,9 +221,9 @@ class FilamentChange(Script): color_change = color_change + (" Z%.2f" % z_pos) if enable_after_macro: - color_change = color_change + "\n" + after_macro + color_change = color_change + after_macro + "\n" - color_change = color_change + "\n;END FilamentChange plugin\n" + color_change = color_change + ";END FilamentChange plugin\n" layer_targets = layer_nums.split(",") if len(layer_targets) > 0: