diff --git a/__init__.py b/__init__.py index eb6bdf7..feb6424 100644 --- a/__init__.py +++ b/__init__.py @@ -408,13 +408,18 @@ class FONT3D_PT_FontCreation(bpy.types.Panel): font3d = scene.font3d font3d_data = scene.font3d_data - layout.label(text="font creation") - layout.row().prop(font3d, "import_infix") + layout.row().label(text="Font name import infix:") + layout.row().prop(font3d, "import_infix", text="") layout.row().operator('font3d.create_font_from_objects', text='Create Font') layout.row().operator('font3d.save_font_to_file', text='Save Font To File') layout.row().operator('font3d.toggle_font3d_collection', text='Toggle Collection') - layout.row().operator('font3d.temporaryhelper', text='Temporary Helper') - layout.label(text='DEBUG END') + box = layout.box() + box.label(text="metrics") + box.row().operator(f"{__name__}.add_default_metrics", text='Add Default Metrics') + box.row().operator(f"{__name__}.remove_metrics", text='Remove Metrics') + box.row().operator(f"{__name__}.align_metrics", text='Align Metrics') + box.row().operator(f"{__name__}.align_metrics_to_active_object", text='Align Metrics to Active Object') + layout.row().operator('font3d.temporaryhelper', text='Debug Function Do Not Use') class FONT3D_PT_TextPropertiesPanel(bpy.types.Panel): bl_label = "Text Properties" @@ -487,6 +492,50 @@ class FONT3D_OT_LoadFont(bpy.types.Operator): return {'FINISHED'} +class FONT3D_OT_AddDefaultMetrics(bpy.types.Operator): + """Add default metrics to selected objects""" + bl_idname = f"{__name__}.add_default_metrics" + bl_label = "Add default metrics" + bl_options = {'REGISTER', 'UNDO'} + + def execute(self, context): + objects = bpy.context.selected_objects + butils.add_default_metrics_to_objects(objects) + return {'FINISHED'} + +class FONT3D_OT_RemoveMetrics(bpy.types.Operator): + """Remove metrics from selected objects""" + bl_idname = f"{__name__}.remove_metrics" + bl_label = "Remove metrics" + bl_options = {'REGISTER', 'UNDO'} + + def execute(self, context): + objects = bpy.context.selected_objects + butils.remove_metrics_from_objects(objects) + return {'FINISHED'} + +class FONT3D_OT_AlignMetricsToActiveObject(bpy.types.Operator): + """Align metrics of selected objects to metrics of active object""" + bl_idname = f"{__name__}.align_metrics_to_active_object" + bl_label = "Align metrics to active object" + bl_options = {'REGISTER', 'UNDO'} + + def execute(self, context): + objects = bpy.context.selected_objects + butils.align_metrics_of_objects_to_active_object(objects) + return {'FINISHED'} + +class FONT3D_OT_AlignMetrics(bpy.types.Operator): + """Align metrics of selected objects to each other""" + bl_idname = f"{__name__}.align_metrics" + bl_label = "Align metrics" + bl_options = {'REGISTER', 'UNDO'} + + def execute(self, context): + objects = bpy.context.selected_objects + butils.align_metrics_of_objects(objects) + return {'FINISHED'} + class FONT3D_OT_TemporaryHelper(bpy.types.Operator): """Temp Font 3D""" bl_idname = f"{__name__}.temporaryhelper" @@ -498,7 +547,16 @@ class FONT3D_OT_TemporaryHelper(bpy.types.Operator): scene = bpy.context.scene font3d_data = scene.font3d_data - font3d_data.available_texts.clear() + objects = bpy.context.selected_objects + butils.add_default_metrics_to_objects(objects) + # reference_bound_box = None + # for o in objects: + # bb = o.bound_box + # reference_bound_box = butils.get_max_bound_box(bb, reference_bound_box) + # for o in objects: + # metrics = butils.get_metrics_bound_box(o.bound_box, reference_bound_box) + # butils.add_metrics_obj_from_bound_box(o, metrics) + # bpy.app.timers.register(lambda: butils.remove_metrics_from_objects(objects), first_interval=5) return {'FINISHED'} @@ -663,7 +721,7 @@ class FONT3D_OT_SaveFontToFile(bpy.types.Operator): class FONT3D_OT_CreateFontFromObjects(bpy.types.Operator): - """Create Font from open objects""" + """Create Font from selected objects""" bl_idname = f"{__name__}.create_font_from_objects" bl_label = "Create Font" bl_options = {'REGISTER', 'UNDO'} @@ -685,13 +743,13 @@ class FONT3D_OT_CreateFontFromObjects(bpy.types.Operator): added_font = False + # TODO: do not clear font3d_data.available_fonts.clear() Font.fonts = {} - currentObjects = [] - for o in bpy.data.objects: + for o in context.selected_objects: if o.name not in currentObjects: - if font3d.import_infix in o.name: + if font3d.import_infix in o.name and not butils.is_metrics_obj(o): uc = o.users_collection regex = f"{font3d.import_infix}(.)*" name = re.sub(regex, "", o.name) @@ -801,6 +859,10 @@ classes = ( FONT3D_PT_TextManagement, FONT3D_PT_FontCreation, FONT3D_PT_TextPropertiesPanel, + FONT3D_OT_AddDefaultMetrics, + FONT3D_OT_RemoveMetrics, + FONT3D_OT_AlignMetricsToActiveObject, + FONT3D_OT_AlignMetrics, FONT3D_OT_TemporaryHelper, FONT3D_OT_PlaceText, FONT3D_OT_LoadFont,