mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
Update AddCoolingProfile.py
Update AddCoolingProfile.py Un-trapped ValueError in line 782. It might also be an IndexError. I left it open. Update AddCoolingProfile.py Change an IndexError to a ValueError
This commit is contained in:
parent
99b198339a
commit
03aa64448a
1 changed files with 44 additions and 15 deletions
|
@ -286,7 +286,7 @@ class AddCoolingProfile(Script):
|
||||||
"description": "For machines with independent layer cooling fans. Leaving a fan running while the other nozzle is printing can help with oozing. You can pick the speed % for the idle nozzle layer cooling fan to hold at.",
|
"description": "For machines with independent layer cooling fans. Leaving a fan running while the other nozzle is printing can help with oozing. You can pick the speed % for the idle nozzle layer cooling fan to hold at.",
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"default_value": false,
|
"default_value": false,
|
||||||
"enabled": "enable_off_fan_speed_enable"
|
"enabled": "enable_off_fan_speed_enable and self.extruder_count > 1"
|
||||||
},
|
},
|
||||||
"off_fan_speed":
|
"off_fan_speed":
|
||||||
{
|
{
|
||||||
|
@ -297,7 +297,7 @@ class AddCoolingProfile(Script):
|
||||||
"minimum_value": 0,
|
"minimum_value": 0,
|
||||||
"maximum_value": 100,
|
"maximum_value": 100,
|
||||||
"unit": "% ",
|
"unit": "% ",
|
||||||
"enabled": "enable_off_fan_speed_enable and enable_off_fan_speed"
|
"enabled": "enable_off_fan_speed_enable and enable_off_fan_speed and self.extruder_count > 1"
|
||||||
},
|
},
|
||||||
"enable_off_fan_speed_enable":
|
"enable_off_fan_speed_enable":
|
||||||
{
|
{
|
||||||
|
@ -378,13 +378,35 @@ class AddCoolingProfile(Script):
|
||||||
if script_count > 0:
|
if script_count > 0:
|
||||||
# Set 'Remove M106 lines' to "false" if there is already an instance of this script running.
|
# Set 'Remove M106 lines' to "false" if there is already an instance of this script running.
|
||||||
self._instance.setProperty("delete_existing_m106", "value", False)
|
self._instance.setProperty("delete_existing_m106", "value", False)
|
||||||
|
self._instance.setProperty("enable_off_fan_speed_enable", "value", False)
|
||||||
if self.extruder_count > 1:
|
if self.extruder_count > 1:
|
||||||
if self.extruder_list[0].getProperty("machine_extruder_cooling_fan_number", "value") != self.extruder_list[1].getProperty("machine_extruder_cooling_fan_number", "value"):
|
if self.extruder_list[0].getProperty("machine_extruder_cooling_fan_number", "value") != self.extruder_list[1].getProperty("machine_extruder_cooling_fan_number", "value"):
|
||||||
self._instance.setProperty("enable_off_fan_speed_enable", "value", True)
|
self._instance.setProperty("enable_off_fan_speed_enable", "value", True)
|
||||||
if bool(self.global_stack.getProperty("machine_heated_bed", "value")):
|
if bool(self.global_stack.getProperty("machine_heated_bed", "value")):
|
||||||
self._instance.setProperty("enable_bv_fan", "value", True)
|
self._instance.setProperty("enable_bv_fan", "value", True)
|
||||||
|
|
||||||
def execute(self, data):
|
def execute(self, data):
|
||||||
|
"""
|
||||||
|
Collect the settings from Cura and from this script
|
||||||
|
params:
|
||||||
|
t0_fan thru t3_fan: The fan numbers for up to 4 layer cooling circuits
|
||||||
|
fan_mode: Whether the fan scale will be 0-255 PWM (when true) or 0-1 RepRap (when false)
|
||||||
|
bed_adhesion: Is only important if a raft is enabled
|
||||||
|
print_seuence: Options are slightly different if in One-at-a-Time mode
|
||||||
|
is_multi-fan: Used to distinguish between a multi-extruder with a single fan for each nozzle, or one fan for both nozzles.
|
||||||
|
is_multi_extr_print: For the slight difference in handling a multi-extruder printer and a print that only uses one of the extruders.
|
||||||
|
fan_list: A list of fan speeds (even numbered items) and layer numbers (odd numbered items)
|
||||||
|
feature_speed_list: A list of the speeds for each ';TYPE:' in the gcode
|
||||||
|
feature_name_list: The list of each 'TYPE' in the gcode
|
||||||
|
off_fan_speed: The speed that will be maintained by the fan for the inactive extruder (for an anti-oozing effect)
|
||||||
|
init_fan: The fan number of the first extruder used in a print
|
||||||
|
delete_existing_m106: The first instance of the script in the post processing list should remove the CUra M106 lines. Following instances should not delete the changes made by the first instance.
|
||||||
|
feature_fan_combing: Whether or not to shut the cooling fan off during travel moves.
|
||||||
|
the_start_layer: When in By Feature this is the user selected start of the fan changes.
|
||||||
|
the_end_layer: When in By Feature this is the user selected end of the fan changes
|
||||||
|
the_end_is_enabled: When in By Feature, if the fan control ends before the print ends, then this will enable the Final Fan Speed to carry through to the print end.
|
||||||
|
|
||||||
|
"""
|
||||||
# Exit if the gcode has been previously post-processed.
|
# Exit if the gcode has been previously post-processed.
|
||||||
if ";POSTPROCESSED" in data[0]:
|
if ";POSTPROCESSED" in data[0]:
|
||||||
return data
|
return data
|
||||||
|
@ -396,8 +418,9 @@ class AddCoolingProfile(Script):
|
||||||
# For 4.x versions that don't have the 0-1 option
|
# For 4.x versions that don't have the 0-1 option
|
||||||
try:
|
try:
|
||||||
fan_mode = not bool(self.extruder_list[0].getProperty("machine_scale_fan_speed_zero_to_one", "value"))
|
fan_mode = not bool(self.extruder_list[0].getProperty("machine_scale_fan_speed_zero_to_one", "value"))
|
||||||
except:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
bed_adhesion = (self.extruder_list[0].getProperty("adhesion_type", "value"))
|
bed_adhesion = (self.extruder_list[0].getProperty("adhesion_type", "value"))
|
||||||
print_sequence = str(self.global_stack.getProperty("print_sequence", "value"))
|
print_sequence = str(self.global_stack.getProperty("print_sequence", "value"))
|
||||||
|
|
||||||
|
@ -454,7 +477,7 @@ class AddCoolingProfile(Script):
|
||||||
# Catch a possible input error.
|
# Catch a possible input error.
|
||||||
if the_end_layer < the_start_layer:
|
if the_end_layer < the_start_layer:
|
||||||
the_end_layer = the_start_layer
|
the_end_layer = the_start_layer
|
||||||
except:
|
except ValueError:
|
||||||
the_end_layer = -1 # If there is an input error then default to the entire gcode file.
|
the_end_layer = -1 # If there is an input error then default to the entire gcode file.
|
||||||
|
|
||||||
# Get the speed for each feature
|
# Get the speed for each feature
|
||||||
|
@ -480,7 +503,7 @@ class AddCoolingProfile(Script):
|
||||||
if the_end_layer == -1 or the_end_is_enabled == False:
|
if the_end_layer == -1 or the_end_is_enabled == False:
|
||||||
the_end_layer = len(data) + 2
|
the_end_layer = len(data) + 2
|
||||||
|
|
||||||
# For multi-extruder printers with separate fans the 'idle' nozzle fan can be left on for ooze control
|
# For multi-extruder printers with separate cooling fans the 'idle' nozzle fan can be left on for ooze control
|
||||||
off_fan_speed = 0
|
off_fan_speed = 0
|
||||||
if self.extruder_count > 1:
|
if self.extruder_count > 1:
|
||||||
if self.getSettingValueByKey("enable_off_fan_speed"):
|
if self.getSettingValueByKey("enable_off_fan_speed"):
|
||||||
|
@ -494,7 +517,7 @@ class AddCoolingProfile(Script):
|
||||||
number_of_raft_layers = 0
|
number_of_raft_layers = 0
|
||||||
layer_0_index = 0
|
layer_0_index = 0
|
||||||
# Catch the number of raft layers.
|
# Catch the number of raft layers.
|
||||||
for l_num in range(1,10,1):
|
for l_num in range(1,len(data) - 1):
|
||||||
layer = data[l_num]
|
layer = data[l_num]
|
||||||
if ";LAYER:-" in layer:
|
if ";LAYER:-" in layer:
|
||||||
number_of_raft_layers += 1
|
number_of_raft_layers += 1
|
||||||
|
@ -511,7 +534,7 @@ class AddCoolingProfile(Script):
|
||||||
T2_used = False
|
T2_used = False
|
||||||
T3_used = False
|
T3_used = False
|
||||||
# Bypass the file header and ending gcode.
|
# Bypass the file header and ending gcode.
|
||||||
for num in range(1,len(data)-1,1):
|
for num in range(1,len(data)-1):
|
||||||
lines = data[num]
|
lines = data[num]
|
||||||
if "T0" in lines:
|
if "T0" in lines:
|
||||||
T0_used = True
|
T0_used = True
|
||||||
|
@ -635,10 +658,10 @@ class AddCoolingProfile(Script):
|
||||||
layer = data[layer_num]
|
layer = data[layer_num]
|
||||||
data[layer_num] = re.sub(";MESH:NOMESH", ";MESH:NONMESH", layer)
|
data[layer_num] = re.sub(";MESH:NOMESH", ";MESH:NONMESH", layer)
|
||||||
data = self._add_travel_comment(data, layer_0_index)
|
data = self._add_travel_comment(data, layer_0_index)
|
||||||
|
|
||||||
if bool(self.getSettingValueByKey("bv_fan_speed_control_enable")):
|
if bool(self.getSettingValueByKey("bv_fan_speed_control_enable")):
|
||||||
data = self._control_bv_fan(data)
|
data = self._control_bv_fan(data)
|
||||||
|
|
||||||
# Single Fan "By Layer"
|
# Single Fan "By Layer"
|
||||||
if by_layer_or_feature == "by_layer" and not is_multi_fan:
|
if by_layer_or_feature == "by_layer" and not is_multi_fan:
|
||||||
return self._single_fan_by_layer(data, layer_0_index, fan_list, t0_fan)
|
return self._single_fan_by_layer(data, layer_0_index, fan_list, t0_fan)
|
||||||
|
@ -681,11 +704,12 @@ class AddCoolingProfile(Script):
|
||||||
this_fan = str(t0_fan)
|
this_fan = str(t0_fan)
|
||||||
start_index = str(len(multi_fan_data))
|
start_index = str(len(multi_fan_data))
|
||||||
for num in range(0,15,2):
|
for num in range(0,15,2):
|
||||||
|
|
||||||
# The fan_list may not be in ascending order. Get the lowest layer number
|
# The fan_list may not be in ascending order. Get the lowest layer number
|
||||||
try:
|
try:
|
||||||
if int(fan_list[num]) < int(start_index):
|
if int(fan_list[num]) < int(start_index):
|
||||||
start_index = str(fan_list[num])
|
start_index = str(fan_list[num])
|
||||||
except:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
# Move the start point if delete_existing_m106 is false
|
# Move the start point if delete_existing_m106 is false
|
||||||
start_index = int(start_index) + int(layer_0_index)
|
start_index = int(start_index) + int(layer_0_index)
|
||||||
|
@ -706,12 +730,13 @@ class AddCoolingProfile(Script):
|
||||||
elif line == "T3":
|
elif line == "T3":
|
||||||
prev_fan = this_fan
|
prev_fan = this_fan
|
||||||
this_fan = t3_fan
|
this_fan = t3_fan
|
||||||
|
# With Active Tool tracked - now the body of changes can start
|
||||||
for l_index in range(int(start_index),len(multi_fan_data)-1,1):
|
for l_index in range(int(start_index),len(multi_fan_data)-1,1):
|
||||||
modified_data = ""
|
modified_data = ""
|
||||||
layer = multi_fan_data[l_index]
|
layer = multi_fan_data[l_index]
|
||||||
fan_lines = layer.split("\n")
|
fan_lines = layer.split("\n")
|
||||||
for fan_line in fan_lines:
|
for fan_line in fan_lines:
|
||||||
# Prepare to shut down the previous fan and start the next one.
|
# Prepare to turn off the previous fan and start the next one.
|
||||||
if fan_line.startswith("T"):
|
if fan_line.startswith("T"):
|
||||||
if fan_line == "T0": this_fan = str(t0_fan)
|
if fan_line == "T0": this_fan = str(t0_fan)
|
||||||
if fan_line == "T1": this_fan = str(t1_fan)
|
if fan_line == "T1": this_fan = str(t1_fan)
|
||||||
|
@ -751,6 +776,7 @@ class AddCoolingProfile(Script):
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if ";LAYER:" in line:
|
if ";LAYER:" in line:
|
||||||
layer_number = str(line.split(":")[1])
|
layer_number = str(line.split(":")[1])
|
||||||
|
continue
|
||||||
if int(layer_number) >= int(the_start_layer) and int(layer_number) < int(the_end_layer)-1:
|
if int(layer_number) >= int(the_start_layer) and int(layer_number) < int(the_end_layer)-1:
|
||||||
temp = line.split(" ")[0]
|
temp = line.split(" ")[0]
|
||||||
try:
|
try:
|
||||||
|
@ -836,8 +862,9 @@ class AddCoolingProfile(Script):
|
||||||
temp = line.split(" ")[0]
|
temp = line.split(" ")[0]
|
||||||
try:
|
try:
|
||||||
name_index = feature_name_list.index(temp)
|
name_index = feature_name_list.index(temp)
|
||||||
except:
|
except IndexError:
|
||||||
name_index = -1
|
name_index = -1
|
||||||
|
|
||||||
if name_index != -1:
|
if name_index != -1:
|
||||||
modified_data += line + "\n" + feature_speed_list[name_index] + this_fan + "\n"
|
modified_data += line + "\n" + feature_speed_list[name_index] + this_fan + "\n"
|
||||||
current_fan_speed = str(feature_speed_list[name_index].split("S")[1])
|
current_fan_speed = str(feature_speed_list[name_index].split("S")[1])
|
||||||
|
@ -848,6 +875,7 @@ class AddCoolingProfile(Script):
|
||||||
current_fan_speed = "0"
|
current_fan_speed = "0"
|
||||||
else:
|
else:
|
||||||
modified_data += line + "\n"
|
modified_data += line + "\n"
|
||||||
|
|
||||||
# If an end layer is defined - Insert the final speed and set the other variables to Final Speed to finish the file
|
# If an end layer is defined - Insert the final speed and set the other variables to Final Speed to finish the file
|
||||||
# There cannot be a 'break' here because if there are multiple fan numbers they still need to be shut off and turned on.
|
# There cannot be a 'break' here because if there are multiple fan numbers they still need to be shut off and turned on.
|
||||||
elif line == ";LAYER:" + str(the_end_layer):
|
elif line == ";LAYER:" + str(the_end_layer):
|
||||||
|
@ -857,6 +885,7 @@ class AddCoolingProfile(Script):
|
||||||
else:
|
else:
|
||||||
# Layer and Tool get inserted into modified_data above. All other lines go into modified_data here
|
# Layer and Tool get inserted into modified_data above. All other lines go into modified_data here
|
||||||
if not line.startswith("T") and not line.startswith(";LAYER:"): modified_data += line + "\n"
|
if not line.startswith("T") and not line.startswith(";LAYER:"): modified_data += line + "\n"
|
||||||
|
|
||||||
if modified_data.endswith("\n"): modified_data = modified_data[0: - 1]
|
if modified_data.endswith("\n"): modified_data = modified_data[0: - 1]
|
||||||
multi_fan_data[l_index] = modified_data
|
multi_fan_data[l_index] = modified_data
|
||||||
modified_data = ""
|
modified_data = ""
|
||||||
|
@ -950,7 +979,7 @@ class AddCoolingProfile(Script):
|
||||||
return comment_data
|
return comment_data
|
||||||
|
|
||||||
def _control_bv_fan(self, bv_data: str) -> str:
|
def _control_bv_fan(self, bv_data: str) -> str:
|
||||||
# Control the chamber fan
|
# Control any secondary fan. Can be used for an Auxilliary/Chamber fan
|
||||||
bv_start_layer = self.getSettingValueByKey("bv_fan_start_layer") - 1
|
bv_start_layer = self.getSettingValueByKey("bv_fan_start_layer") - 1
|
||||||
bv_end_layer = self.getSettingValueByKey("bv_fan_end_layer")
|
bv_end_layer = self.getSettingValueByKey("bv_fan_end_layer")
|
||||||
bv_fan_nr = self.getSettingValueByKey("bv_fan_nr")
|
bv_fan_nr = self.getSettingValueByKey("bv_fan_nr")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue