Start script on open blender 3D

I have written up a script for my model. But there is a bit of a problem with it. as in I have to run the script every time I open the file. I want the script to run automatically when I open the blender File.

Make that script a Text datablock (if not already), ensure the name ends with .py and tick the Register checkbox.

Other solution is to open your model from a shortcut or a batch (or shell) command.
For example a batch command stored in a .bat file:

E:\\Programs\\Blender\blender.exe --python myscript.py

P.S. I had the impression that putting a init.py file aside to the blend file will work as well, now I try it but it does not work. Is this the case or am I missing something?

A init.py will not do anything, unless it’s part of a multi-file addon in a folder (python module). Upon enabling an addon, init.py will be called and is responsible to configure/load all other classes/files of the addon.

I see, in the same spirit this is how it would be much better, instead of embedding the script inside Blender it will be much handy to edit it externally (let’s say you use versioning in blend files, or you use a good editor like atom or sublime). However this register checkbox will come handy as you said to start the external import.


import os
import sys

dir_path = os.path.dirname(os.path.dirname(__file__))

if dir_path not in sys.path:
    sys.path.append(dir_path)

# myscript is myscript.py or whatever name of the file you want
from myscript import *