-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
42 lines (32 loc) · 930 Bytes
/
util.py
File metadata and controls
42 lines (32 loc) · 930 Bytes
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
from typing import List
from dataclasses import dataclass
ORIGINAL_GCODE_FILE = "./originalLayer.gcode"
NEW_FILE_SUFFIX = "LayerTest.gcode"
PRINT_START_SIGN = ";TYPE:Bottom surface\n"
PRINT_END_SIGN = ";WIPE_START\n"
@dataclass
class FileLines:
startPos: int
startLines: List[str]
endPos: int
endLines: List[str]
drawLines: List[str]
def getAllFileLines():
with open(ORIGINAL_GCODE_FILE) as fin:
gcodeLines = fin.readlines()
startPos = gcodeLines.index(PRINT_START_SIGN)
startLines = gcodeLines[0:startPos+1]
endPos = gcodeLines.index(PRINT_END_SIGN)
endLines = gcodeLines[endPos:]
drawLines = gcodeLines[startPos+1:endPos]
drawLines = [dl for dl in drawLines if dl.startswith('G1')]
return FileLines(
startPos,
startLines,
endPos,
endLines,
drawLines
)
def writeFileLines(outputLines, fileNamePrefix):
with open(fileNamePrefix + NEW_FILE_SUFFIX, 'w') as fout:
fout.writelines(outputLines)