mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Update InsertAtLayerChange.py
I removed the period from the G-code to insert label for consistency. I also added a third option to this called "Skip layers". This allows you to insert gcode with a specific number of layers skipped (i.e. skip layers 1 will insert gcode every other layer, skip layers 3 will insert every fourth). As an example, this change allowed me to insert a nozzle cleaning routine in my gcode without having to run it EVERY layer.
This commit is contained in:
parent
4cc8d7cf57
commit
09d1becf1e
1 changed files with 19 additions and 6 deletions
|
@ -26,27 +26,40 @@ class InsertAtLayerChange(Script):
|
||||||
},
|
},
|
||||||
"gcode_to_add":
|
"gcode_to_add":
|
||||||
{
|
{
|
||||||
"label": "G-code to insert.",
|
"label": "G-code to insert",
|
||||||
"description": "G-code to add before or after layer change.",
|
"description": "G-code to add before or after layer change.",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"default_value": ""
|
"default_value": ""
|
||||||
|
},
|
||||||
|
"skip_layers":
|
||||||
|
{
|
||||||
|
"label": "Skip layers",
|
||||||
|
"description": "Number of layers to skip between insertions (0 for every layer).",
|
||||||
|
"type": "int",
|
||||||
|
"default_value": 0,
|
||||||
|
"minimum_value": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
def execute(self, data):
|
def execute(self, data):
|
||||||
gcode_to_add = self.getSettingValueByKey("gcode_to_add") + "\n"
|
gcode_to_add = self.getSettingValueByKey("gcode_to_add") + "\n"
|
||||||
|
skip_layers = self.getSettingValueByKey("skip_layers")
|
||||||
|
count = 0
|
||||||
for layer in data:
|
for layer in data:
|
||||||
# Check that a layer is being printed
|
# Check that a layer is being printed
|
||||||
lines = layer.split("\n")
|
lines = layer.split("\n")
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if ";LAYER:" in line:
|
if ";LAYER:" in line:
|
||||||
index = data.index(layer)
|
index = data.index(layer)
|
||||||
if self.getSettingValueByKey("insert_location") == "before":
|
if count == 0:
|
||||||
layer = gcode_to_add + layer
|
if self.getSettingValueByKey("insert_location") == "before":
|
||||||
else:
|
layer = gcode_to_add + layer
|
||||||
layer = layer + gcode_to_add
|
else:
|
||||||
|
layer = layer + gcode_to_add
|
||||||
|
|
||||||
data[index] = layer
|
data[index] = layer
|
||||||
|
|
||||||
|
count = (count + 1) % (skip_layers + 1)
|
||||||
break
|
break
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue