kopia lustrzana https://github.com/inkstitch/inkstitch
batch lettering: output file name (#3617)
rodzic
4771b94df3
commit
7ae5a4b91b
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import string
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
@ -133,10 +134,10 @@ class BatchLettering(InkstitchExtension):
|
||||||
|
|
||||||
path = tempfile.mkdtemp()
|
path = tempfile.mkdtemp()
|
||||||
files = []
|
files = []
|
||||||
for text in texts:
|
for i, text in enumerate(texts):
|
||||||
stitch_plan, lettering_group = self.generate_stitch_plan(text, text_positioning_path)
|
stitch_plan, lettering_group = self.generate_stitch_plan(text, text_positioning_path)
|
||||||
for file_format in file_formats:
|
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)
|
self.reset_document(lettering_group, text_positioning_path)
|
||||||
|
|
||||||
|
@ -167,9 +168,13 @@ class BatchLettering(InkstitchExtension):
|
||||||
parent.insert(index, text_positioning_path)
|
parent.insert(index, text_positioning_path)
|
||||||
lettering_group.delete()
|
lettering_group.delete()
|
||||||
|
|
||||||
def generate_output_file(self, file_format, path, text, stitch_plan):
|
def generate_output_file(self, file_format, path, text, stitch_plan, iteration):
|
||||||
text = text.replace('\n', '')
|
allowed_characters = string.ascii_letters + string.digits
|
||||||
output_file = os.path.join(path, f"{text}.{file_format}")
|
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':
|
if file_format == 'svg':
|
||||||
document = deepcopy(self.document.getroot())
|
document = deepcopy(self.document.getroot())
|
||||||
|
|
Ładowanie…
Reference in New Issue