Page MenuHome

Reload text datablock if Modified
Closed, ArchivedPublicPATCH

Description

Project: Blender Extensions
Tracker: Py Scripts Upload
Blender: 2.55
Category: Text Editor
Python: 3.1
Script name: reload_if_modified
Wiki page: http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Text_Editor/Reload_if_Modified
Author(s): Dany Lebel (axon_d)
Status: Closed

This addon will automatically reload a text datablock if its source file does not corresponds to the last blendfile version. This must be checked for each file wanted to be updated automatically. It has no effect on internal text datablock.

To test the addon:
1
create a text file in blender and save it on disc. Check the "Reload if Modified" checkbox on the header bar of the text editor.
2
edit this text in an external text editor and save your changes.
3
get back to blender and the text is reloaded automatically.

Keep in mind that it will only update text datablock that are visible in the UI (for example, text in another screen won't be reloaded). But this is not so much a problem since blender always save text internally(unless I'm wrong). External save must be done explicitly.


Event Timeline

This looks nice.
But i have to confess i don't really understand how the relationship between the function and the boolprop works.
Could you explain how that works?
Because it looks curious how you mingle functionality and layout stuff in one function.

I attached a bool property to text type to determine if a text data block must be reloaded when its source file has changed. I appended the function like a draw one because this bring the possibility for the function to occur every redraw.

So the bpy.context.space_data.text is evaluated if it has an attribute called 'reload_if_modified. If not, then there is no text data block in the current text editor and it stops.

If yes, and the text has been set as in memory, then the property reload_if_modified is set to False, cause we don't want to evaluate the external file if the text is internal. And this reinitialises it to False.

Else: So this means that there is a text, data block and it is saved to an external file. so we display the bool property for the user to be able to set it as reload_if_modified if he wants to. and if it is set to True, then the data block check if it is_modified.

If yes, then it reloads.

Just tested this script as described in the description with revision 39104, and the automatic reloading didn't happen:

RuntimeError: Calling operator "bpy.ops.text.reload" error, can't modify blend data in this state (drawing/rendering)

Hi,
Just a Reminder for people to Join the Mail List.
If you have not already, please visit this page:
http://lists.blender.org/mailman/listinfo/bf-extensions-cvs
& join the list.

Hi,
Due to changes to the api including the merging of bmesh, several addons are outdated.
Please, if you are the author of an addon check your script with blender revision 44256 or newer.
That is builds made After blender 2.62 official release.
I would ask that updates be made to your addon before the Blender 2.63 release.
6-8 weeks away.
This allows time for the api to become more exposed & bmesh to stablize furthur.
If you need help, drop into irc freenode #blenderpython or #blendercoders & feel welcome to ask questions.
At the time of 2.63 release, scripts that are not repaired or in active developement will have their tracker page marked "Closed"
this will not affect your links to the tracker, similar to closing scripts in 2.49b, the page will be still availible & can be re-opened.

Thanks for your understanding & patience during these Exciting Times.
Brendon.

hi,
Currently I'm still unsure of the working state of this addon.
I'm closing this page for now. as part of 2.63 cleanup.
If you want to resubmit your addon please let me know & this page can be reopened easily.
Thanks for your addon & interest in Blender.
Brendon.

Brendon Murphy (meta-androcto) changed the task status from Unknown Status to Unknown Status.Apr 16 2012, 11:01 AM

Hi,
It's ok to close. The script did worked in the past, but the implementation was not as good as it should. Some changes in the api since many revision prevent this kind of approach now. When I'll have time, I may work again on it to make it more correctly.
Dany