My main goal is to achieve that this script file will open My_file.blend, apply my script on it, render and save an image to output path
I would suggest using the Blender command line interface (CLI) to trigger the script execution and rendering. The CLI is described in the Blender documentation.
For instance you could start Blender from the command line, let it run a python script and then render a frame using the following command (you will have to add the correct paths to the relevant files). The following command renders frame 0 of project.blend after the script.py has been executed.
.\blender.exe project.blend -b -P script.py -o //frame_ -f 0
--background starts Blender without a user interface.
--python allows to run a script.
--render-output defines how the rendered files will be named and where they will be stored.
// denotes the current working directory.
--render-frame tells Blender to render a specific frame.
In case you don't want to execute Blender with this command manually, you can use
subprocess in a another python script to start Blender. The following function is an example of how you could start Blender from another python script. As arguments you need to pass the path to Blender, the project and the script and it will start another process that runs Blender with these arguments.
import subprocess def run_blender(blender, project, script): output = subprocess.check_output([blender, project, '--background', '--python', script, '--render-output', '//frame_', '--render-frame', '0']) print(output.decode("utf-8"))
Start with the basics
blender --background my.blend --python myscript.py
where myscript.py contains your logic and
To produce the render
in your script you can change just about anything e.g.
You can also pass parameters and include multiple python scripts.