From e8fd0d824304e7bf58f155ebe35f099c0e5aeb51 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Thu, 31 Oct 2024 19:34:31 +0100 Subject: [PATCH] reset text on depsgraph update --- __init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/__init__.py b/__init__.py index e10855d..34db8cd 100644 --- a/__init__.py +++ b/__init__.py @@ -1485,6 +1485,20 @@ def on_frame_changed(self, dummy): # TODO PERFORMANCE: only on demand butils.set_text_on_curve(t) +@persistent +def on_depsgraph_update(scene, depsgraph): + for u in depsgraph.updates: + if f"{utils.prefix()}_linked_textobject" in u.id.keys() \ + and f"{utils.prefix()}_type" in u.id.keys() \ + and u.id[f"{utils.prefix()}_type"] == 'textobject': + linked_textobject = u.id[f"{utils.prefix()}_linked_textobject"] + if u.is_updated_geometry and len(scene.abc3d_data.available_texts) > linked_textobject and not "prevent_recursion" in u.id: + u.id["prevent_recursion"] = True + butils.set_text_on_curve(scene.abc3d_data.available_texts[linked_textobject]) + elif "prevent_recursion" in u.id.keys(): + del u.id["prevent_recursion"] + + def register(): for cls in classes: bpy.utils.register_class(cls) @@ -1501,6 +1515,9 @@ def register(): if on_frame_changed not in bpy.app.handlers.frame_change_post: bpy.app.handlers.frame_change_post.append(on_frame_changed) + if on_depsgraph_update not in bpy.app.handlers.depsgraph_update_post: + bpy.app.handlers.depsgraph_update_post.append(on_depsgraph_update) + butils.run_in_main_thread(butils.clear_available_fonts) # butils.run_in_main_thread(butils.load_installed_fonts) butils.run_in_main_thread(butils.update_available_fonts)