[fix] deletion fixes+

and some smaller cosmetic changes
This commit is contained in:
jrkb 2025-05-31 17:47:47 +02:00
parent 8470425d20
commit d61607c75d
2 changed files with 45 additions and 11 deletions

View file

@ -336,7 +336,7 @@ class ABC3D_UL_texts(bpy.types.UIList):
class ABC3D_PT_Panel(bpy.types.Panel):
bl_label = f"{__name__} panel"
bl_label = f"{utils.prefix()} Panel"
bl_category = "ABC3D"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
@ -344,6 +344,9 @@ class ABC3D_PT_Panel(bpy.types.Panel):
def draw(self, context):
layout = self.layout
row = layout.row()
row.label(text=f"{utils.prefix()} v{utils.get_version_string()}")
icon = "NONE"
if len(context.scene.abc3d_data.available_fonts) == 0:
icon = "ERROR"
@ -439,11 +442,9 @@ class ABC3D_PT_FontList(bpy.types.Panel):
row = box.row()
row.label(text="File and Memory optimization")
row = box.row()
row.operator(f"{__name__}.refresh_fonts", text="Refresh Font list from disk")
row.operator(f"{__name__}.refresh_fonts", text="Refresh font list from disk")
row = box.row()
row.operator(
f"{__name__}.unload_unused_glyphs", text="Unload unused glyphs from memory"
)
row.operator(f"{__name__}.unload_unused_glyphs", text="Unload unused glyphs")
class ABC3D_PT_TextPlacement(bpy.types.Panel):
@ -1013,7 +1014,6 @@ class ABC3D_OT_LoadInstalledFonts(bpy.types.Operator):
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
print("EXECUTE LOAD INSTALLED FONTS")
scene = bpy.context.scene
if self.load_into_memory:
@ -1234,6 +1234,7 @@ class ABC3D_OT_RemoveText(bpy.types.Operator):
def execute(self, context):
abc3d_data = context.scene.abc3d_data
lock_depsgraph_updates(auto_unlock_s=-1)
if abc3d_data.active_text_index < 0:
butils.ShowMessageBox(
title="No text selected",
@ -1269,6 +1270,7 @@ class ABC3D_OT_RemoveText(bpy.types.Operator):
butils.simply_delete_objects(remove_list)
abc3d_data.available_texts.remove(i)
unlock_depsgraph_updates()
return {"FINISHED"}
@ -2033,6 +2035,7 @@ import time
@persistent
def on_depsgraph_update(scene, depsgraph):
if not bpy.context.mode.startswith("EDIT") and not are_depsgraph_updates_locked():
lock_depsgraph_updates(auto_unlock_s=-1)
for u in depsgraph.updates:
if (
butils.get_key("text_id") in u.id.keys()
@ -2046,12 +2049,17 @@ def on_depsgraph_update(scene, depsgraph):
if text_properties.text_object == u.id.original:
# nothing to do
pass
else:
elif butils.is_text_object_legit(u.id.original):
# must be duplicate
link_text_object_with_new_text_properties(u.id.original, scene)
else:
# must be new thing
elif (
butils.is_text_object_legit(u.id.original)
and len(u.id.original.users_collection) > 0
):
# must be a new thing, maybe manually created or so
link_text_object_with_new_text_properties(u.id.original, scene)
butils.clean_text_properties()
unlock_depsgraph_updates()
def register():

View file

@ -647,6 +647,17 @@ def is_glyph_used(glyph_alternates):
return False
def clean_text_properties():
abc3d_data = bpy.context.scene.abc3d_data
remove_these = []
for i, text_properties in enumerate(abc3d_data.available_texts):
if len(text_properties.text_object.users_collection) <= 0:
remove_these.append(i)
remove_these.reverse()
for i in remove_these:
abc3d_data.available_texts.remove(i)
def clean_fontcollection(fontcollection=None):
if fontcollection is None:
fontcollection = bpy.data.collections.get("ABC3D")
@ -1336,6 +1347,21 @@ def test_finding():
transfer_text_object_to_text_properties(o, t)
def is_text_object_legit(text_object):
must_have_keys = [
get_key("font_name"),
get_key("face_name"),
get_key("text"),
get_key("type"),
]
for key in must_have_keys:
if key not in text_object:
return False
if text_object[get_key("type")] != "textobject":
return False
return True
# def detect_texts():
# scene = bpy.context.scene
# abc3d_data = scene.abc3d_data
@ -1478,6 +1504,8 @@ def set_text_on_curve(
mom = text_properties.text_object
if mom.type != "CURVE":
return False
if len(mom.users_collection) < 1:
return False
distribution_type = "CALCULATE" if is_bezier(mom) else "FOLLOW_PATH"
@ -2042,8 +2070,6 @@ def add_default_metrics_to_objects(objects=None, overwrite_existing=False):
targets = []
reference_bound_box = None
for o in objects:
if not hasattr(o, "parent"):
print(f"{o.name} has not a PARENTNTNTNTNTNNTNTNTNTNTN")
is_possibly_glyph = is_glyph(o)
if is_possibly_glyph:
metrics = []