depsgraph detect texts

implementing in depsgraph allows for duplication
This commit is contained in:
jrkb 2025-05-25 15:35:52 +02:00
parent c27cf41368
commit 10e57dd46a

View file

@ -1791,6 +1791,11 @@ def compare_text_object_with_object(t, o, strict=False):
# if
return True
def link_text_object_with_new_text_properties(text_object, scene = None):
lock_depsgraph_updates(auto_unlock_s=-1)
butils.link_text_object_with_new_text_properties(text_object, scene)
unlock_depsgraph_updates()
def detect_text():
lock_depsgraph_updates(auto_unlock_s=-1)
@ -1921,10 +1926,8 @@ def are_depsgraph_updates_locked():
import time
@persistent
def on_depsgraph_update(scene, depsgraph):
global depsgraph_updates_locked
print("DEPSGRAPH:: BEGIN")
if not bpy.context.mode.startswith("EDIT") and not are_depsgraph_updates_locked():
for u in depsgraph.updates:
@ -1940,26 +1943,21 @@ def on_depsgraph_update(scene, depsgraph):
print(f" is {len(scene.abc3d_data.available_texts)} bigger than {text_id=} is true?")
# butils.detect_texts()
if len(scene.abc3d_data.available_texts) > text_id:
text_properties = scene.abc3d_data.available_texts[text_id]
print(" YES")
print(" is ? text object is not u.id")
if scene.abc3d_data.available_texts[text_id].text_object != u.id:
print(" yes")
print(f" is ? {text_properties.text_object.name=} is {u.id.name=}")
if text_properties.text_object == u.id.original:
print(" yes by id")
else:
print(" no")
# must be duplicate
link_text_object_with_new_text_properties(u.id.original, scene)
print(" no by id")
else:
# must be new thing
print(" NO, LINK TO NEW TEXTOBJECT")
link_text_object_with_new_text_properties(u.id.original, scene)
print(" NO")
print("DEPSGRAPH:: done textobject")
# lock_depsgraph_updates()
# def later():
# if butils.lock_depsgraph_update_n_times <= 0:
# butils.set_text_on_curve(
# scene.abc3d_data.available_texts[text_id]
# )
# elif butils.lock_depsgraph_update_n_times <= 0:
# butils.lock_depsgraph_update_n_times -= 1
# butils.run_in_main_thread(later)
if are_depsgraph_updates_locked():
print(" L O C K E D")
print("DEPSGRAPH:: done")
@ -1993,6 +1991,7 @@ def register():
butils.run_in_main_thread(butils.update_available_fonts)
butils.run_in_main_thread(load_used_glyphs)
butils.run_in_main_thread(butils.update_types)
butils.run_in_main_thread(detect_text)
Font.init()