Is it possible to programmatically create a Blender file (.blend) using Python?

I know that Python is the standard scripting language to use inside Blender, but I have not found a way to create a .blend file using python.

What I want to do is not use python inside blender, but rather use blender (libs?) Inside python. "

My planned workflow will be as follows:

  • Define some parameters for my model;
  • Define a β€œgenerative recipe” to create the appropriate Blender objects that will be saved in the file;
  • Create a python script to save the parameters and procedures. When the script starts, some .blend file is created in the same folder;
  • Use Blender to render the model. If you need to change the model, make changes to the script, run it again and open it again.
+4
source share
2 answers

You can start the new Blender process from any application (C ++, Python, or even the command line) and tell the new process to start the script file (written in Python). This script will generate your geometry and then save the new scene in a file blend.

To start a new Blender process and make it execute script use:
blender.exe --background --python "c:\path to\script.py"

+4
source

, python python. .

python script script . bpy.ops.wm.save_as_mainfile(filepath="path/to/myfilename")

script, blender, python script, , . , .

script , blender -b -P myscript.py -b, blender .

+8

Source: https://habr.com/ru/post/1538291/


All Articles