From fc9b1b65b081eb8a7b20a0cf0259fa5497420dc6 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Tue, 13 May 2025 15:38:37 +0200 Subject: [PATCH] autodetect names earlier this makes it obvious to the user if autodetect works --- __init__.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/__init__.py b/__init__.py index 94aa3f2..42f4f8c 100644 --- a/__init__.py +++ b/__init__.py @@ -1248,6 +1248,18 @@ class ABC3D_OT_CreateFontFromObjects(bpy.types.Operator): wm = context.window_manager return wm.invoke_props_dialog(self) + def do_autodetect_names(self, name: str): + ifxsplit = name.split("_") + if len(ifxsplit) < 4: + print(f"name could not be autodetected {name}") + print("split:") + print(ifxsplit) + return self.font_name, self.face_name, self.import_infix + detected_font_name = f"{ifxsplit[1]}_{ifxsplit[2]}" + detected_face_name = ifxsplit[3] + detected_import_infix = f"{ifxsplit[1]}_{ifxsplit[2]}_{ifxsplit[3]}" + return detected_font_name, detected_face_name, detected_import_infix + def draw(self, context): layout = self.layout if len(context.selected_objects) == 0: @@ -1255,7 +1267,11 @@ class ABC3D_OT_CreateFontFromObjects(bpy.types.Operator): layout.row().label(text="Please select your glyphs first.", icon="INFO") else: row = layout.row() - row.prop(self, 'autodetect_names') + row.prop(self, "autodetect_names") + first_object_name = context.selected_objects[-1].name + self.font_name, self.face_name, self.import_infix = ( + self.do_autodetect_names(first_object_name) + ) if self.autodetect_names: scale_y = 0.5 row = layout.row() @@ -1342,13 +1358,7 @@ class ABC3D_OT_CreateFontFromObjects(bpy.types.Operator): print(f"processing {o.name}") process_object = True if self.autodetect_names: - ifxsplit = o.name.split('_') - if len(ifxsplit) < 4: - print( - f"whoops name could not be autodetected {o.name}") - continue - font_name = f"{ifxsplit[1]}_{ifxsplit[2]}" - face_name = ifxsplit[3] + font_name, face_name, input_infix = self.do_autodetect_names(o.name) if butils.is_mesh(o) and not butils.is_metrics_object(o): uc = o.users_collection