Fix gcode parsing for single-line output
Browse files
app.py
CHANGED
|
@@ -73,10 +73,21 @@ def gcode_to_svg(gcode: str) -> str:
|
|
| 73 |
x, y = 0.0, 0.0
|
| 74 |
pen_down = False
|
| 75 |
|
|
|
|
|
|
|
|
|
|
| 76 |
for line in gcode.split("\n"):
|
| 77 |
line = line.strip()
|
| 78 |
-
if not line
|
| 79 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
# Pen state from M280 servo commands
|
| 82 |
if "M280" in line.upper():
|
|
|
|
| 73 |
x, y = 0.0, 0.0
|
| 74 |
pen_down = False
|
| 75 |
|
| 76 |
+
# Split on newlines first, then also split commands that may be on same line
|
| 77 |
+
# Handle gcode that's all on one line by splitting on G0/G1/M commands
|
| 78 |
+
lines = []
|
| 79 |
for line in gcode.split("\n"):
|
| 80 |
line = line.strip()
|
| 81 |
+
if not line:
|
| 82 |
continue
|
| 83 |
+
# Split on gcode commands (G0, G1, G28, M280, etc.)
|
| 84 |
+
parts = re.split(r'(?=[GM]\d)', line)
|
| 85 |
+
for part in parts:
|
| 86 |
+
part = part.strip()
|
| 87 |
+
if part and not part.startswith(";"):
|
| 88 |
+
lines.append(part)
|
| 89 |
+
|
| 90 |
+
for line in lines:
|
| 91 |
|
| 92 |
# Pen state from M280 servo commands
|
| 93 |
if "M280" in line.upper():
|