forked from fieldOfView/Cura-SimpleShapes
-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
TempFanTower.py
190 lines (169 loc) · 8.23 KB
/
TempFanTower.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#------------------------------------------------------------------------------------------------------------------------------------
#
# Cura PostProcessing Script
# Author: 5axes
# Date: January 13, 2020
#
# Description: postprocessing-script to easily define a TempTower and not use 10 changeAtZ-scripts
#
#
#------------------------------------------------------------------------------------------------------------------------------------
#
# Version 1.1 9/01/2020
# Version 1.2 11/01/2020 Fan modification after Bridge
# Version 1.3 18/04/2021 : ChangeLayerOffset += 2
# Version 1.4 18/05/2021 : ChangeLayerOffset
#
# Version 1.5 15/02/2022 Change Int for Layeroffset & changelayer
# Version 1.6 05/08/2022 Option maintainbridgevalue
#------------------------------------------------------------------------------------------------------------------------------------
from ..Script import Script
from UM.Application import Application
from UM.Logger import Logger
__version__ = '1.6'
class TempFanTower(Script):
def __init__(self):
super().__init__()
def getSettingDataString(self):
return """{
"name": "TempFanTower",
"key": "TempFanTower",
"metadata": {},
"version": 2,
"settings":
{
"startTemperature":
{
"label": "Starting Temperature",
"description": "The starting temperature of the TempTower",
"type": "int",
"default_value": 220,
"minimum_value": 100,
"maximum_value": 300,
"minimum_value_warning": 170,
"maximum_value_warning": 280
},
"temperaturechange":
{
"label": "Temperature Increment",
"description": "The temperature change of each block, can be positive or negative. If you want 220 and then 210, you need to set this to -10",
"type": "int",
"default_value": -5,
"minimum_value": -100,
"maximum_value": 100,
"minimum_value_warning": -20,
"maximum_value_warning": 20
},
"changelayer":
{
"label": "Change Layer",
"description": "How many layers needs to be printed before the temperature should be changed",
"type": "int",
"default_value": 52,
"minimum_value": 1,
"maximum_value": 1000,
"minimum_value_warning": 5,
"maximum_value_warning": 100
},
"changelayeroffset":
{
"label": "Change Layer Offset",
"description": "If the print has a base, indicate the number of layers from which to start the changes.",
"type": "int",
"default_value": 5,
"minimum_value": 0,
"maximum_value": 1000,
"maximum_value_warning": 100
},
"usefanvalue":
{
"label": "Activate Fan Tower",
"description": "Activate also a fan variation to create a Fan Tower",
"type": "bool",
"default_value": false
},
"fanchange":
{
"label": "Fan values in %",
"description": "The fan speed change of each block, list value separated by a comma ';' ",
"type": "str",
"default_value": "100;40;0",
"enabled": "usefanvalue"
},
"maintainbridgevalue":
{
"label": "Keep Bridge Fan Value",
"description": "Don't Change the Bridge Fan value",
"type": "bool",
"default_value": false,
"enabled": "usefanvalue"
}
}
}"""
def execute(self, data):
startTemperature = self.getSettingValueByKey("startTemperature")
temperaturechange = self.getSettingValueByKey("temperaturechange")
changelayer = int(self.getSettingValueByKey("changelayer"))
ChangeLayerOffset = int(self.getSettingValueByKey("changelayeroffset"))
ChangeLayerOffset += 2 # Modification to take into account the numbering offset in Gcode
# layer_index = 0 for initial Block 1= Start Gcode normaly first layer = 0
fanvalues_str = self.getSettingValueByKey("fanchange")
fanvalues = fanvalues_str.split(";")
nbval = len(fanvalues) - 1
usefan = False
if (nbval>0):
usefan = bool(self.getSettingValueByKey("usefanvalue"))
bridgevalue = bool(self.getSettingValueByKey("maintainbridgevalue"))
else:
usefan = False
bridgevalue = False
currentTemperature = startTemperature
currentfan = int((int(fanvalues[0])/100)*255) # 100% = 255 pour ventilateur
idl=0
afterbridge = False
for layer in data:
layer_index = data.index(layer)
lines = layer.split("\n")
for line in lines:
if line.startswith("M106 S") and ((layer_index-ChangeLayerOffset)>0) and (usefan) :
if afterbridge or not bridgevalue :
line_index = lines.index(line)
currentfan = int((int(fanvalues[idl])/100)*255) # 100% = 255 pour ventilateur
lines[line_index] = "M106 S"+str(int(currentfan))+ " ; FAN MODI"
afterbridge -= 1
else :
line_index = lines.index(line)
afterbridge += 1
if line.startswith("M107") and ((layer_index-ChangeLayerOffset)>0) and (usefan):
afterbridge = 1
line_index = lines.index(line)
if line.startswith(";BRIDGE") :
afterbridge = 0
line_index = lines.index(line)
if line.startswith(";LAYER:"):
line_index = lines.index(line)
if (layer_index==ChangeLayerOffset):
lines.insert(line_index + 1, ";TYPE:CUSTOM LAYER")
lines.insert(line_index + 2, "M104 S"+str(currentTemperature))
idl=0
if (usefan):
currentfan = int((int(fanvalues[idl])/100)*255) # 100% = 255 pour ventilateur
lines.insert(line_index + 3, "M106 S"+str(currentfan))
if ((layer_index-ChangeLayerOffset) % changelayer == 0) and ((layer_index-ChangeLayerOffset)>0):
if (usefan) and (idl < nbval):
idl += 1
currentfan = int((int(fanvalues[idl])/100)*255) # 100% = 255 pour ventilateur
lines.insert(line_index + 1, ";TYPE:CUSTOM FAN")
lines.insert(line_index + 2, "M106 S"+str(int(currentfan)))
else:
currentTemperature += temperaturechange
lines.insert(line_index + 1, ";TYPE:CUSTOM TEMP")
lines.insert(line_index + 2, "M104 S"+str(currentTemperature))
if (usefan):
# On repart à la valeur de départ
idl = 0
currentfan = int((int(fanvalues[idl])/100)*255) # 100% = 255 pour ventilateur
lines.insert(line_index + 3, "M106 S"+str(int(currentfan)))
result = "\n".join(lines)
data[layer_index] = result
return data