From ce90ed815e4ecd16258154a11fde4e1d85abb515 Mon Sep 17 00:00:00 2001
From: Jochen Ullrich <kontakt@ju-hh.de>
Date: Fri, 8 Dec 2023 16:50:31 +0100
Subject: [PATCH] Fixes #29, inject define_object before first instruction

---
 preprocess_cancellation.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/preprocess_cancellation.py b/preprocess_cancellation.py
index 4e1c2d1..526d3aa 100644
--- a/preprocess_cancellation.py
+++ b/preprocess_cancellation.py
@@ -274,18 +274,18 @@ def preprocess_cura(infile):
 
     infile.seek(0)
     for line in infile:
-        yield line
         if line.strip() and not line.startswith(";"):
+            # Inject custom marker
+            yield from header(len(known_objects))
+            for mesh_id, hull in known_objects.values():
+                yield from define_object(
+                    mesh_id,
+                    center=hull.center(),
+                    polygon=hull.exterior(),
+                )
+            yield line
             break
-
-    # Inject custom marker
-    yield from header(len(known_objects))
-    for mesh_id, hull in known_objects.values():
-        yield from define_object(
-            mesh_id,
-            center=hull.center(),
-            polygon=hull.exterior(),
-        )
+        yield line
 
     current_object = None
     for line in infile: