-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Altered SearchAndReplace, InsertAtLayerChange and TimeLapse
All three files get new options: SearchAndReplace - Added range of layers, and options to skip the StartUp and Ending Gcode. InsertAtLayerChange - Added Insert Frequency and layer range. Added multi-line input. TimeLapse - Added Insert Frequency
- Loading branch information
1 parent
7f62744
commit 44c6cf1
Showing
3 changed files
with
388 additions
and
105 deletions.
There are no files selected for viewing
140 changes: 119 additions & 21 deletions
140
plugins/PostProcessingPlugin/scripts/InsertAtLayerChange.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,150 @@ | ||
# Copyright (c) 2020 Ultimaker B.V. | ||
# Cura is released under the terms of the LGPLv3 or higher. | ||
# Created by Wayne Porter | ||
# Created by Wayne Porter. | ||
# Altered January of 2023 by GregValiant (Greg Foresi) | ||
# Support for multi-line insertions | ||
# Insertion start and end layers. Numbers are consistent with the Cura Preview (base1) | ||
# Frequency of Insertion (one time, every layer, every 2nd, 3rd, 5th, 10th, 25th, 50th, 100th) | ||
|
||
from ..Script import Script | ||
import re | ||
|
||
class InsertAtLayerChange(Script): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def getSettingDataString(self): | ||
return """{ | ||
"name": "Insert at layer change", | ||
"name": "Insert at Layer Change", | ||
"key": "InsertAtLayerChange", | ||
"metadata": {}, | ||
"version": 2, | ||
"settings": | ||
{ | ||
"insert_location": | ||
"insert_frequency": | ||
{ | ||
"label": "When to insert", | ||
"description": "Whether to insert code before or after layer change.", | ||
"label": "How often to insert", | ||
"description": "Every so many layers starting with the Start Layer OR as single insertion at a specific layer.", | ||
"type": "enum", | ||
"options": {"before": "Before", "after": "After"}, | ||
"default_value": "before" | ||
"options": { | ||
"once_only": "One insertion only", | ||
"every_layer": "Every Layer", | ||
"every_2nd": "Every 2nd", | ||
"every_3rd": "Every 3rd", | ||
"every_5th": "Every 5th", | ||
"every_10th": "Every 10th", | ||
"every_25th": "Every 25th", | ||
"every_50th": "Every 50th", | ||
"every_100th": "Every 100th"}, | ||
"default_value": "every_layer" | ||
}, | ||
"start_layer": | ||
{ | ||
"label": "Starting Layer", | ||
"description": "Layer to start the insertion at. Use layer numbers from the Cura Preview. Enter '1' to start at gcode LAYER:0. If you need to start from the beginning of a raft enter '-5'.", | ||
"type": "int", | ||
"default_value": 1, | ||
"minimum_value": -5, | ||
"enabled": "insert_frequency != 'once_only'" | ||
}, | ||
"end_layer_enabled": | ||
{ | ||
"label": "Enable End Layer", | ||
"description": "Check to use an ending layer for the insertion. Use layer numbers from the Cura Preview.", | ||
"type": "bool", | ||
"default_value": false, | ||
"enabled": "insert_frequency != 'once_only'" | ||
}, | ||
"end_layer": | ||
{ | ||
"label": "Ending Layer", | ||
"description": "Layer to end the insertion at. Enter '-1' for entire file (or disable this setting). Use layer numbers from the Cura Preview.", | ||
"type": "str", | ||
"default_value": "-1", | ||
"enabled": "end_layer_enabled and insert_frequency != 'once_only'" | ||
}, | ||
"single_end_layer": | ||
{ | ||
"label": "Layer # for Single Insertion.", | ||
"description": "Layer for a single insertion of the Gcode. Use the layer numbers from the Cura Preview.", | ||
"type": "str", | ||
"default_value": "", | ||
"enabled": "insert_frequency == 'once_only'" | ||
}, | ||
"gcode_to_add": | ||
{ | ||
"label": "G-code to insert.", | ||
"description": "G-code to add before or after layer change.", | ||
"description": "G-code to add at start of the layer. Use a comma to delimit multi-line commands. EX: G28 X Y,M220 S100,M117 HELL0. NOTE: All inserted text will be converted to upper-case as some firmwares don't understand lower-case.", | ||
"type": "str", | ||
"default_value": "" | ||
} | ||
} | ||
}""" | ||
|
||
def execute(self, data): | ||
gcode_to_add = self.getSettingValueByKey("gcode_to_add") + "\n" | ||
for layer in data: | ||
# Check that a layer is being printed | ||
lines = layer.split("\n") | ||
for line in lines: | ||
if ";LAYER:" in line: | ||
index = data.index(layer) | ||
if self.getSettingValueByKey("insert_location") == "before": | ||
layer = gcode_to_add + layer | ||
else: | ||
layer = layer + gcode_to_add | ||
#Initialize variables | ||
mycode = self.getSettingValueByKey("gcode_to_add").upper() | ||
the_start_layer = int(self.getSettingValueByKey("start_layer"))-1 | ||
the_end_layer = self.getSettingValueByKey("end_layer").lower() | ||
the_end_is_enabled = self.getSettingValueByKey("end_layer_enabled") | ||
when_to_insert = self.getSettingValueByKey("insert_frequency") | ||
start_here = False | ||
real_num = 0 | ||
if the_end_layer == "-1" or not the_end_is_enabled: | ||
the_end_layer = "9999999999" | ||
#If the gcode_to_enter is multi-line then replace the commas with newline characters | ||
if mycode != "": | ||
if "," in mycode: | ||
mycode = re.sub(",", "\n",mycode) | ||
gcode_to_add = mycode + "\n" | ||
#Get the insertion frequency | ||
if when_to_insert == "every_layer": | ||
freq = 1 | ||
if when_to_insert == "every_2nd": | ||
freq = 2 | ||
if when_to_insert == "every_3rd": | ||
freq = 3 | ||
if when_to_insert == "every_5th": | ||
freq = 5 | ||
if when_to_insert == "every_10th": | ||
freq = 10 | ||
if when_to_insert == "every_25th": | ||
freq = 25 | ||
if when_to_insert == "every_50th": | ||
freq = 50 | ||
if when_to_insert == "every_100th": | ||
freq = 100 | ||
if when_to_insert == "once_only": | ||
the_search_layer = int(self.getSettingValueByKey("single_end_layer"))-1 | ||
|
||
#Add the post processor name to the gcode file | ||
data[0] += "; Insert at Layer Change (Insert; " + str(mycode) + " Insert Frequency; " + when_to_insert + " layer)" + "\n" | ||
|
||
data[index] = layer | ||
break | ||
#Single insertion | ||
index = 0 | ||
if when_to_insert == "once_only": | ||
for layer in data: | ||
lines = layer.split("\n") | ||
for line in lines: | ||
if ";LAYER:" in line: | ||
layer_number = int(line.split(":")[1]) | ||
if layer_number == int(the_search_layer): | ||
index = data.index(layer) | ||
lines.insert(1,gcode_to_add[0:-1]) | ||
data[index] = "\n".join(lines) | ||
break | ||
#Multiple insertions | ||
if when_to_insert != "once_only": | ||
for layer in data: | ||
lines = layer.split("\n") | ||
for line in lines: | ||
if ";LAYER:" in line: | ||
layer_number = int(line.split(":")[1]) | ||
if layer_number >= int(the_start_layer)-1 and layer_number <= int(the_end_layer)-1: | ||
index = data.index(layer) | ||
real_num = layer_number - int(the_start_layer) | ||
if int(real_num / freq) - (real_num / freq) == 0: | ||
lines.insert(1,gcode_to_add[0:-1]) | ||
data[index] = "\n".join(lines) | ||
break | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.