-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCheckFirstSpeed.py
More file actions
250 lines (199 loc) · 8.92 KB
/
CheckFirstSpeed.py
File metadata and controls
250 lines (199 loc) · 8.92 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#------------------------------------------------------------------------------------------------------------------------------------
#
# Cura PostProcessing Script
# Author: 5axes
# Date: January 04, 2024
#
# Description: postprocessing script to modifiy the first layer infill and Check the first Wall Speed Bug Cura 5.6
#
#------------------------------------------------------------------------------------------------------------------------------------
#
# Version 1.0 04/01/2024
#
#------------------------------------------------------------------------------------------------------------------------------------
import string
import re # To perform the search
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.Logger import Logger
from enum import Enum
__version__ = '1.0'
class Section(Enum):
"""Enum for section type."""
NOTHING = 0
SKIRT = 1
INNER_WALL = 2
OUTER_WALL = 3
INFILL = 4
SKIN = 5
SKIN2 = 6
def is_begin_layer_line(line: str) -> bool:
"""Check if current line is the start of a layer section.
Args:
line (str): Gcode line
Returns:
bool: True if the line is the start of a layer section
"""
return line.startswith(";LAYER:")
def is_begin_type_line(line: str) -> bool:
"""Check if current line is the start of a new type section.
Args:
line (str): Gcode line
Returns:
bool: True if the line is the start of a new type section
"""
return line.startswith(";TYPE:")
def is_retract_line(line: str) -> bool:
"""Check if current line is a retract segment.
Args:
line (str): Gcode line
Returns:
bool: True if the line is a retract segment
"""
return "G1" in line and "F" in line and "E" in line and not "X" in line and not "Y" in line and not "Z" in line
def is_extrusion_line(line: str) -> bool:
"""Check if current line is a standard printing segment.
Args:
line (str): Gcode line
Returns:
bool: True if the line is a standard printing segment
"""
return "G1" in line and "X" in line and "Y" in line and "E" in line
def is_not_extrusion_line(line: str) -> bool:
"""Check if current line is a rapid movement segment.
Args:
line (str): Gcode line
Returns:
bool: True if the line is a standard printing segment
"""
return "G0" in line and "X" in line and "Y" in line and not "E" in line
def is_begin_skin_segment_line(line: str) -> bool:
"""Check if current line is the start of an skin.
Args:
line (str): Gcode line
Returns:
bool: True if the line is the start of an skin section
"""
return line.startswith(";TYPE:SKIN")
def is_begin_inner_wall_segment_line(line: str) -> bool:
"""Check if current line is the start of an inner wall.
Args:
line (str): Gcode line
Returns:
bool: True if the line is the start of an inner wall section
"""
return line.startswith(";TYPE:WALL-INNER")
def is_begin_outer_wall_segment_line(line: str) -> bool:
"""Check if current line is the start of an outer wall.
Args:
line (str): Gcode line
Returns:
bool: True if the line is the start of an outer wall section
"""
return line.startswith(";TYPE:WALL-OUTER")
class CheckFirstSpeed(Script):
def __init__(self):
super().__init__()
def getSettingDataString(self):
return """{
"name": "Check First Speed",
"key": "CheckFirstSpeed",
"metadata": {},
"version": 2,
"settings":
{
"modifyinfillspeed":
{
"label": "Modify Infill Speed",
"description": "Option to modify First layer infill speed value.",
"type": "bool",
"default_value": true
},
"infillspeed":
{
"label": "First layer infill speed",
"description": "First layer infill speed value.",
"type": "float",
"unit": "mm/s",
"default_value": 30,
"minimum_value": 1,
"maximum_value": 100,
"maximum_value_warning": 50,
"enabled": "modifyinfillspeed"
},
"replacewallspeed":
{
"label": "Replace Wall Speed",
"description": "Option to replace wall speed on first layer (Cura 5.6 bug fix).",
"type": "bool",
"default_value": true
}
}
}"""
# Get the value
def GetDataExtruder(self,id_ex,key,dec=0):
extruder_stack = Application.getInstance().getExtruderManager().getActiveExtruderStacks()
GetVal = extruder_stack[id_ex].getProperty(key, "value")
return GetVal
def execute(self, data):
InfillSpeed = float(self.getSettingValueByKey("infillspeed")) * 60
checkFirstWallSpeed = bool(self.getSettingValueByKey("replacewallspeed"))
modifyFirstInfillSpeed = bool(self.getSettingValueByKey("modifyinfillspeed"))
# machine_extruder_count
extruder_count=int(Application.getInstance().getGlobalContainerStack().getProperty("machine_extruder_count", "value"))
extruder_count = extruder_count-1
extruder_stack = Application.getInstance().getExtruderManager().getActiveExtruderStacks()
extruder_nr=len(extruder_stack)
extruder_nr = int(Application.getInstance().getExtruderManager().getActiveExtruderStacks()[0].getProperty("extruder_nr", "value"))
extruder_id=int(Application.getInstance().getGlobalContainerStack().getProperty("wall_extruder_nr", "value"))
if extruder_id == -1 :
extruder_id=extruder_nr
if extruder_id>extruder_count :
extruder_id=extruder_count
# speed_print_layer_0
self._speed_print_layer_0 = float(self.GetDataExtruder(extruder_id,"speed_print_layer_0"))
Logger.log('d', "extruder_count --> " + str(extruder_count))
Logger.log('d', "extruder_nr --> " + str(extruder_nr))
Logger.log('d', "extruder_id --> " + str(extruder_id))
Logger.log('d', "speed_print_layer_0 --> " + str(self._speed_print_layer_0) )
idl=0
for layer in data:
layer_index = data.index(layer)
lines = layer.split("\n")
for line in lines:
if is_begin_layer_line(line):
# Logger.log('d', 'layer_index : {:d}'.format(layer_index))
# Logger.log('d', 'layer_lines : {}'.format(line))
if line.startswith(";LAYER:0"):
idl=1
else :
idl=0
if is_begin_type_line(line) and idl > 0:
if is_begin_skin_segment_line(line) and modifyFirstInfillSpeed :
idl=4
ReplaceSpeedInstruction="F" + str(InfillSpeed)
# Logger.log('d', 'Skin line : {}'.format(ReplaceSpeedInstruction))
elif is_begin_inner_wall_segment_line(line) and checkFirstWallSpeed :
idl=3
ReplaceSpeedInstruction="F" + str(self._speed_print_layer_0*60)
# Logger.log('d', 'Inner Wall line : {}'.format(ReplaceSpeedInstruction))
elif is_begin_outer_wall_segment_line(line) and checkFirstWallSpeed :
idl=2
ReplaceSpeedInstruction="F" + str(self._speed_print_layer_0*60)
# Logger.log('d', 'Outer Wall line : {}'.format(ReplaceSpeedInstruction))
else :
idl=1
if idl >= 2 and is_extrusion_line(line):
searchF = re.search(r"F(\d*\.?\d*)", line)
if searchF:
line_index = lines.index(line)
save_F=float(searchF.group(1))
instructionF="F"+str(searchF.group(1))
# Logger.log('d', 'save_F : {:f}'.format(save_F))
# Logger.log('d', 'line : {}'.format(line))
# Logger.log('d', 'line replace : {}'.format(line.replace(instructionF,ReplaceSpeedInstruction)))
lines[line_index]=line.replace(instructionF,ReplaceSpeedInstruction)
result = "\n".join(lines)
data[layer_index] = result
return data