From 65d037d335f044738d5b1a0fcfa9aa6eebd3f4b4 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sat, 3 Jan 2015 03:00:02 +0100 Subject: [PATCH] Fix preamble generation for very short patches --- embroider.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/embroider.py b/embroider.py index f038307ac..f582487d2 100644 --- a/embroider.py +++ b/embroider.py @@ -391,18 +391,25 @@ class EmbroideryObject: i = 0 nextp = PyEmb.Point(patch.stitches[i].x, -patch.stitches[i].y) - for j in xrange(1, 4): - if locs[-1] == nextp: - i += 1 - nextp = PyEmb.Point(patch.stitches[i].x, -patch.stitches[i].y) - locs.append(self.make_preamble_stitch(locs[-1], nextp)) + try: + for j in xrange(1, 4): + if locs[-1] == nextp: + i += 1 + nextp = PyEmb.Point(patch.stitches[i].x, -patch.stitches[i].y) + locs.append(self.make_preamble_stitch(locs[-1], nextp)) + except IndexError: + # happens when the patch is very short and we increment i beyond the number of stitches + pass dbg.write("preamble locations: %s\n" % locs) for j in add_preamble[1:]: - stitch = deepcopy(locs[int(j)]) - stitch.color = patch.color - stitch.jumpStitch = False - emb.addStitch(stitch) + try: + stitch = deepcopy(locs[int(j)]) + stitch.color = patch.color + stitch.jumpStitch = False + emb.addStitch(stitch) + except IndexError: + pass jumpStitch = False lastStitch = newStitch