diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2025-03-30 04:26:50 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-30 06:26:50 +0200 |
| commit | 7ae5a4b91b1c8a738e0f36c9fbbf52c688f4d989 (patch) | |
| tree | 292c22e62d9b8ba4452c8ef31bc66b77a0689a2c /lib/extensions | |
| parent | 4771b94df303a3bb9c3ada5f4d2efe202b40d8a7 (diff) | |
batch lettering: output file name (#3617)
Diffstat (limited to 'lib/extensions')
| -rw-r--r-- | lib/extensions/batch_lettering.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/extensions/batch_lettering.py b/lib/extensions/batch_lettering.py index a1fa3c43..31d24e5f 100644 --- a/lib/extensions/batch_lettering.py +++ b/lib/extensions/batch_lettering.py @@ -5,6 +5,7 @@ import json import os +import string import sys import tempfile from copy import deepcopy @@ -133,10 +134,10 @@ class BatchLettering(InkstitchExtension): path = tempfile.mkdtemp() files = [] - for text in texts: + for i, text in enumerate(texts): stitch_plan, lettering_group = self.generate_stitch_plan(text, text_positioning_path) for file_format in file_formats: - files.append(self.generate_output_file(file_format, path, text, stitch_plan)) + files.append(self.generate_output_file(file_format, path, text, stitch_plan, i)) self.reset_document(lettering_group, text_positioning_path) @@ -167,9 +168,13 @@ class BatchLettering(InkstitchExtension): parent.insert(index, text_positioning_path) lettering_group.delete() - def generate_output_file(self, file_format, path, text, stitch_plan): - text = text.replace('\n', '') - output_file = os.path.join(path, f"{text}.{file_format}") + def generate_output_file(self, file_format, path, text, stitch_plan, iteration): + allowed_characters = string.ascii_letters + string.digits + filtered_text = ''.join(x for x in text if x in allowed_characters) + if filtered_text: + filtered_text = f'-{filtered_text}' + file_name = f'{iteration:03d}{filtered_text:.8}' + output_file = os.path.join(path, f"{file_name}.{file_format}") if file_format == 'svg': document = deepcopy(self.document.getroot()) |
