Skip to content

Commit

Permalink
Update LittleUtilities.py
Browse files Browse the repository at this point in the history
Added "Lift Head Retract and Prime
  • Loading branch information
GregValiant committed Jul 3, 2023
1 parent 25299ac commit b874c3c
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions plugins/PostProcessingPlugin/scripts/LittleUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
# Renumber Layers - For One-At-A-Time prints. PauseAtHeight and Filament Change act differently.
# Add Extruder End code - this may be fixed in Cura 5.4.
# Add Data Headers (a debugging utility) - Splits the gcode and adds comments between the data sections
# Lift Head Retraction - adds retract and prime to "Lift Head" cooling option for small layers.

from ..Script import Script
from UM.Application import Application
from UM.Message import Message
import re

class LittleUtilities(Script):
Expand All @@ -27,13 +29,14 @@ def getSettingDataString(self):
"pick_a_post":
{
"label": "Pick a Post Processor",
"description": "'Remove Comments' will remove any semi-colons and all text to the right. 'Add Extruder End Gcode' will put any Extruder End Gcode of the last extruder used at the beginning of the Ending Gcode in the file. 'Add Data Headers' is a debugging tool and will split the gcode into sections in the manner it is received from Cura.",
"description": "Remove comments will remove the semi-colon and all text to the right. Add Extruder End Gcode will put any Extruder End Gcode of the last extruder used at the beginning of the Ending Gcode in the file. 'Add Data Headers' will split the gcode into sections in the manner it is received from Cura.",
"type": "enum",
"options": {
"remove_comments": "Remove Comments",
"renumber_layers": "Renumber or Revert layer numbers",
"add_extruder_end": "Add Extruder End Gcode",
"add_data_header": "Add Data Headers"},
"add_data_header": "Add Data Headers",
"lift_retraction": "Lift Retract and Prime"},
"default_value": "remove_comments"
},
"inc_opening":
Expand Down Expand Up @@ -173,7 +176,7 @@ def execute(self, data):

#If the project was sliced 'All at Once' then Exit-------------------------
if one_at_a_time == "all_at_once":
data[0] += "; Little Utilities (Renumber Layers: Disabled: All-At-Once file)\n"
data[0] += "; Little Utilities (Renumber Layers did not run: All-At-Once file)\n"
Message(text = "Little Utilities Renumber Layers: {}".format("Did not run because the Print Sequence is All At Once.")).show()
return data

Expand All @@ -197,10 +200,6 @@ def execute(self, data):
data[num] = layer.replace(temp[0],";LAYER:" + str(lay_num))
lay_num += 1
layer = data[layer0_index - 1]

# Add the post processor name to the file when "Renum" to AllAtOnce-------------------------
renum_string = "Renumber to AllAtOnce"
data[0] += "; L.U.- Renumber Layers: " + renum_string + "\n"
elif renum_layers == "un_renum":

# Revert the numbering to OneAtATime if enabled-----------------------------------------------------------
Expand All @@ -214,10 +213,6 @@ def execute(self, data):
if ";LAYER_COUNT:" in layer:
lay_num = 0
layer = data[layer0_index - 1]

# Add the post processor name to the file when "Revert" to OneAtATime-------------------------
renum_string = "Revert to OneAtATime"
data[0] += "; L.U. - Renumber Layers: " + renum_string + "\n"

# Concatenate extraneous data[items] that Cura adds at model change. This may help post processors that might run after this one. Add the 'MESH:NONMESH' line for consistency.
newdata = []
Expand Down Expand Up @@ -264,5 +259,27 @@ def execute(self, data):
model_lay_count += 1
if ";LAYER:0" in data[num]:
data[num-1] = re.sub(";LAYER_COUNT:(\d*)",";LAYER_COUNT:" + str(model_lay_count), data[num-1])
model_lay_count = 0
return data
model_lay_count = 0
return data
# Lift Head Retract and Prime----------------------------------------------
elif self.getSettingValueByKey("pick_a_post") == "lift_retraction":
extruder = Application.getInstance().getGlobalContainerStack().extruderList
lift_head_enabled = bool(extruder[0].getProperty("cool_lift_head", "value"))
# If Lift Head is not enabled then exit------------------------------------
if not lift_head_enabled:
data[0] += "; Little Utilities (Lift Head Retraction did not run: Lift head is not enabled)\n"
Message(text = "Little Utilities Lift Head: {}".format("Did not run because Lift Head is not enabled in Cura.")).show()
return data
retract_dist = int(extruder[0].getProperty("retraction_amount", "value"))
retract_speed = int(extruder[0].getProperty("retraction_speed", "value"))
lift_retract = "G1 F" + str(retract_speed * 60) + " E-" + str(retract_dist)
lift_prime = "G1 F" + str(retract_speed * 60) + " E" + str(retract_dist)
for lay_num in range(2, len(data)-1,1):
layer = data[lay_num]
lines = layer.split("\n")
for index, line in enumerate(lines):
if line.startswith(";Small layer"):
lines.insert(index + 1, lift_retract)
lines.insert(index + 4, lift_prime)
data[lay_num] = "\n".join(lines)
return data

0 comments on commit b874c3c

Please sign in to comment.