Using Blender v2.78, auto executing python code / script doesn't seem to work no matter how you're trying to do that.
Following explanations from Blender manual - Scripting & Security
1/ Setting auto execution manually should be possible when Register
is checked in the text editor containing your python code.
NOT working : script does not run automatically (even if you also check Auto Execution
in User Preferences
)
2/ Setting auto execution from command line should be possible when -y
(or --enable-autoexec
) is provided as argument.
NOT working : this parameter should override User preferences
(and factory startup by the way, see : Auto-run scripts security options)
Here is the dummy code I put in an empty blender file to do very basic testing (trying to "see" startup process using different ways ... but since script doesn't seem to be started, app handler is also probably not called):
import bpy
def onStartup():
print("[DEBUG] doing something on startup")
bpy.ops.mesh.primitive_monkey_add()
print("[INFOS] Blender v" + bpy.app.version_string)
onStartup()
from bpy.app.handlers import persistent
@persistent
def load_handler(dummy):
print("[DEBUG] handler called AFTER blender file is loaded (" + bpy.data.filepath + ")")
onStartup()
bpy.app.handlers.load_post.append(load_handler)
autoruntest.py
. $\endgroup$