-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathInhibFan.py
120 lines (103 loc) · 4.73 KB
/
InhibFan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#------------------------------------------------------------------------------------------------------------------------------------
#
# Cura PostProcessing Script
# Author: 5axes
# Date: July 13, 2022
#
# Description: postprocessing-script to supress the Fan on First layers
#
#------------------------------------------------------------------------------------------------------------------------------------
#
# Version 1.1 13/07/2022
#
#------------------------------------------------------------------------------------------------------------------------------------
from ..Script import Script
from UM.Application import Application # To get the current printer's settings.
from cura.CuraVersion import CuraVersion # type: ignore
from UM.Message import Message
from UM.Logger import Logger
from UM.i18n import i18nCatalog # Translation
catalog = i18nCatalog("cura")
__version__ = '1.1'
class InhibFan(Script):
def __init__(self):
super().__init__()
def getSettingDataString(self):
return """{
"name": "InhibFan",
"key": "InhibFan",
"metadata": {},
"version": 2,
"settings":
{
"inhiblayer":
{
"label": "Nb of Layers for Fan inhibition",
"description": "Number of Layer where we want to turn off the print cooling fan",
"type": "int",
"default_value": 4,
"minimum_value": 1,
"maximum_value": 100,
"minimum_value_warning": 1,
"maximum_value_warning": 100
},
"extruder_nb":
{
"label": "Extruder Id",
"description": "Define extruder Id in case of multi extruders",
"unit": "",
"type": "int",
"default_value": 1
}
}
}"""
def execute(self, data):
inhiblayer = 0
inhiblayer = int(self.getSettingValueByKey("inhiblayer"))
extruder_id = self.getSettingValueByKey("extruder_nb")
extruder_id = extruder_id -1
# GEt extrud
extrud = Application.getInstance().getGlobalContainerStack().extruderList
# machine_extruder_count
extruder_count=Application.getInstance().getGlobalContainerStack().getProperty("machine_extruder_count", "value")
extruder_count = extruder_count-1
if extruder_id>extruder_count :
extruder_id=extruder_count
cool_fan_speed = extrud[extruder_id].getProperty("cool_fan_speed", "value")
Logger.log('d', 'cool_fan_speed : {}'.format(cool_fan_speed))
setfan = int((int(cool_fan_speed)/100)*255)
current_Layer = 0
idl=0
for layer in data:
layer_index = data.index(layer)
lines = layer.split("\n")
for line in lines:
if line.startswith(";LAYER:") and inhiblayer > 0 :
current_Layer = int(line.split(":")[1])
current_Layer += 1
# If the layer number is smaller than the Nb of Layers for Fan inhibition
if current_Layer <= inhiblayer :
idl=1
# Special analyse for the following layer
elif current_Layer == (inhiblayer + 1) :
line_index = lines.index(line)
next_line=lines[line_index+1]
Logger.log('d', 'next_line : {}'.format(next_line))
# If we have a Fan Instruction leave It
if next_line.startswith("M106 S") :
Logger.log('d', 'Keep the S Value layer {}'.format(current_Layer))
# If we have a Fan turned off leave it like that
elif next_line.startswith("M107") :
Logger.log('d', 'Keep the Fan OFF layer {}'.format(current_Layer))
# If we have nothing then we need to set the fan value to the regular speed
else :
lines.insert(line_index + 1, "M106 S"+str(setfan))
idl=0
else :
idl=0
if line.startswith("M106 S") and idl == 1 :
line_index = lines.index(line)
lines[line_index] = "M107"
result = "\n".join(lines)
data[layer_index] = result
return data