-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathFastFirstInfill.py
170 lines (136 loc) · 5.33 KB
/
FastFirstInfill.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
#------------------------------------------------------------------------------------------------------------------------------------
#
# Cura PostProcessing Script
# Author: 5axes
# Date: November 06, 2021
#
# Description: postprocessing script to modifiy the first layer infill
#
#------------------------------------------------------------------------------------------------------------------------------------
#
# Version 1.0 06/11/2021
# Version 1.1 07/11/2021 Modification for Print Sequence
#
#------------------------------------------------------------------------------------------------------------------------------------
from ..Script import Script
from UM.Logger import Logger
from UM.Application import Application
import re # To perform the search
from enum import Enum
__version__ = '1.1'
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")
class FastFirstInfill(Script):
def __init__(self):
super().__init__()
def getSettingDataString(self):
return """{
"name": "FastFirstInfill",
"key": "FastFirstInfill",
"metadata": {},
"version": 2,
"settings":
{
"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
}
}
}"""
def execute(self, data):
InfillSpeed = float(self.getSettingValueByKey("infillspeed")) * 60
InfillSpeedInstruction = "F" + str(InfillSpeed)
Logger.log('d', 'InfillSpeedInstruction : {}'.format(InfillSpeedInstruction))
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):
idl=2
Logger.log('d', 'layer_lines : {}'.format(line))
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,InfillSpeedInstruction)))
lines[line_index]=line.replace(instructionF,InfillSpeedInstruction)
result = "\n".join(lines)
data[layer_index] = result
return data