-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathChangeFanValue.py
162 lines (136 loc) · 6.31 KB
/
ChangeFanValue.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#------------------------------------------------------------------------------------------------------------------------------------
#
# Cura PostProcessing Script
# Author: 5axes
# Date: January 13, 2020
#
# Description: postprocessing-script to manage Fan Value
#
#
#------------------------------------------------------------------------------------------------------------------------------------
#
# Version 1.1 9/01/2020
#
#------------------------------------------------------------------------------------------------------------------------------------
import string
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 ChangeFanValue(Script):
def __init__(self):
super().__init__()
def getSettingDataString(self):
return """{
"name": "ChangeFanValue",
"key": "ChangeFanValue",
"metadata": {},
"version": 2,
"settings":
{
"usefanvalue":
{
"label": "Set Fan Value on Minimum Time",
"description": "Change the Fan Value on minimum Time situation",
"type": "bool",
"default_value": false
},
"fanchange":
{
"label": "Fan values in %",
"description": "The fan speed change of each block for minimum time Layer situation",
"type": "int",
"unit": "%",
"default_value": 100,
"minimum_value": 1,
"maximum_value": 100,
"minimum_value_warning": 50,
"maximum_value_warning": 100
}
}
}"""
# Get the value
def GetDataExtruder(self,id_ex,key,dec=0):
# Deprecation Warning
# extrud = list(Application.getInstance().getGlobalContainerStack().extruders.values())
extruder_stack = Application.getInstance().getExtruderManager().getActiveExtruderStacks()
GetVal = extruder_stack[id_ex].getProperty(key, "value")
#GetLabel = Application.getInstance().getGlobalContainerStack().getProperty(key, "label")
#GetType = Application.getInstance().getGlobalContainerStack().getProperty(key, "type")
#GetUnit = Application.getInstance().getGlobalContainerStack().getProperty(key, "unit")
return GetVal
def execute(self, data):
usefan = False
fanvalues = 0
usefan = bool(self.getSettingValueByKey("usefanvalue"))
fanvalues = int(self.getSettingValueByKey("fanchange"))
# machine_extruder_count
extruder_count=Application.getInstance().getGlobalContainerStack().getProperty("machine_extruder_count", "value")
extruder_count = extruder_count-1
extruder_id=extruder_count
# cool_min_layer_time
self._cool_min_layer_time = float(self.GetDataExtruder(extruder_id,"cool_min_layer_time"))
Logger.log('d', "cool_min_layer_time --> " + str(self._cool_min_layer_time) )
currentfan = 0
Current_Fan_Value = 0
Current_Layer = 0
setfan = int((int(fanvalues)/100)*255) # 100% = 255 pour ventilateur
#Logger.log('d', "setfan --> " + str(setfan) )
save_time=0
Just_Modi=0
idl=0
for layer in data:
layer_index = data.index(layer)
lines = layer.split("\n")
for line in lines:
if line.startswith(";LAYER:0"):
idl=0
if line.startswith(";LAYER:"):
Current_Layer = int(line.split(":")[1])
if line.startswith("; MODI_FAN"):
Just_Modi=1
if line.startswith("M106 S") and usefan :
if Just_Modi==1 :
Just_Modi=0
else :
line_index = lines.index(line)
Current_Fan_Value = int(line.split("S")[1])
#Logger.log('d', "Current_Fan_Value --> " + str(Current_Fan_Value) )
if idl==1:
lines[line_index] = "; " + line
# M107: Eteindre les ventilateurs
if line.startswith("M107") and (usefan):
line_index = lines.index(line)
Current_Fan_Value=0
if idl==1:
lines[line_index] = "; " + line
if line.startswith(";TIME_ELAPSED:"):
line_index = lines.index(line)
total_time = float(line.split(":")[1])
Layer_time=total_time-save_time
if Layer_time<=self._cool_min_layer_time :
if idl==0:
#Logger.log('d', "Time MODI --> " + str(Layer_time))
#Logger.log('d', "MODI LAYER--> " + str(Current_Layer))
lines.insert(line_index + 1, "; MODI_FAN")
lines.insert(line_index + 2, "M106 S"+str(setfan))
idl=1
Just_Modi=1
else:
if idl==1:
#Logger.log('d', "Reset Time --> " + str(Layer_time) )
#Logger.log('d', "Reset FAN VALUE --> " + str(Current_Fan_Value))
Cline=lines[line_index]
if Current_Fan_Value == 0:
lines.insert(line_index + 1, "M107")
else:
lines.insert(line_index + 1, "M106 S"+str(Current_Fan_Value))
idl=0
save_time=total_time
result = "\n".join(lines)
data[layer_index] = result
return data