How can I make a script run when I open a file? This to be used with registering an handler every time the file is opened.
You can do this somewhat easily, by naming your text block
*.py and checking the
Then the script contained in it will be run every time you open the
.blend file. This is great for registering handlers at the startup of a file.
If the file is a .blend you can use an application handler
import bpy from bpy.app.handlers import persistent @persistent def load_handler(dummy): print("Load Handler:", bpy.data.filepath) bpy.app.handlers.load_post.append(load_handler)
For other file types there is no callback provided, you could iterate over all text files
for t in bpy.data.texts: 'check for previously created' -> exec if new and add to list.
and check for new entries triggered by a timer.
When you are opening .blend file, then you have to also enable "Trusted source" option. See it in following image:
It is not enabled by default, because there are security reason for that. You can do very bad thing with Python (delete files on your disk, send spam, etc.)