Hi,
The link to download no longer works. Can you reshare this? Is there anything else similar available? I also would like a script that will save all text datablocks to their external file if it exists.
Thanks
reload_on = False #reload from external file or save all from internal
import bpy
area = bpy.context.area
for text in bpy.data.texts:
area.spaces[0].text = text
if text.filepath != '' and reload_on == True:
bpy.ops.text.reload()
if text.filepath != '' and text.is_dirty:
bpy.ops.text.save()
Updated the addon as it was doing exactly what I needed. Though the code update is tied to depsgraph update (so now it’s updated only when the viewport was updated). Any ideas how to update it more often?
Put it in a timer. When doing say, make sure you read the section of the timers documentation that talks about threading and safely updating scene data.
Thank you for the suggestion, totally forgot about the timers option. Updated the script above.
I’ve read the timer documentation, not sure if it applies to my case since I’m going to have just 1 thread with example code bellow (code is simplified though).
Sure, it’s possible to start separate timers for each text and then I’d need to store them in queue and run from the main timer thread and I guess that might be more optimal since there won’t be any checks except check for empty queue if there are no texts marked. But then the timer that checks would need to know the text it’s going to check and since text object reference is unreliable then I’d also need to use text’s names and keep track of their changes…
So I think it should work fine for the most purposes the way it is.
import bpy
def check_texts_every_second():
for text in bpy.data.texts:
if text.is_in_memory:
continue
if text.is_modified and text.reload_if_modified:
text.from_string(new_text)
return 1 # every second
bpy.app.timers.register(check_texts_every_second)