I know Python is the standard scripting language for use inside Blender, but I didn't find a way to create a .blend file with python.
What I want to do is not to use python inside blender, but rather "use blender (libs?) inside python".
My planned workflow would be the following:
Blender uses the Python programming language for its scripting API. The Blender Python API is based on Python 3. It is integrated deeply, used for writing add-ons, generating user interface layouts, and import and export of many file formats.
Python in Blender This interpreter runs scripts to draw the user interface and is used for some of Blender's internal tools as well. Blender's embedded interpreter provides a typical Python environment, so code from tutorials on how to write Python scripts can also be run with Blender's interpreter.
You can start a new Blender process from any application (a C++, Python app or even command line) and tell the new process to run a script file (written in Python). This script will generate your geometry and then can save the new scene to a blend
file.
To start a new Blender process and force it to execute a script use:blender.exe --background --python "c:\path to\script.py"
There is an experimental option that allows you to build your own copy of blender as a python module to use like a standard python module. This page is about all the help you will get for it.
I would recommend you write your python script as a blender script to be run inside blender. You can automate saving the file using bpy.ops.wm.save_as_mainfile(filepath="path/to/myfilename")
You can run a script inside blender that generates a blender text block that you can then run as a python script, select all, delete and re-run. You can also easily reload an external file as a text block in blender if you prefer an external text editor for it's features.
You can also use your plan to generate the script yourself which you can then run using blender with blender -b -P myscript.py
the -b
option tells blender to run in the background without a GUI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With