autoexec python code / script doesn't seem to work 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 &amp; 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)
Found a solution !

Ages ago (before we were relying only on Internet), I was told "If you try searching for some explanation start with man man and dig further from there (yep, I was surrounded by prehistorical nerds)". So an old reflex just came back, I've done an old fashion man blender from my terminal and found the following option :

--python-text &lt;name&gt;
       Run the given Python script text block


Since your text editor creates a block called Text by default, you just need to specify this block name ... and it works as expected !

While it shouldn't, the online manual seems, somehow, providing less information than the one available locally !

So, execution of random python code can be executed automatically with the following command :


  blender -y yourfile.blend --python-text Text


or 


  blender --enable-autoexec yourfile.blend --python-text Text


where Text is the name / label or your text block (you can get it from the header of your text editor view)



As pointed by batFINGER and dr. Sybren, another easy way is to modify the name generated by default when you create a new text block, by adding ".py" extension to it !