Like the title says, I want to create a Python (or Node.js program, although I think Python would be a lot better for this) that creates a new Blender file and is able to change the colour of the default cube. I want to do something more advanced than that, but I think once I learn how to change the colour of the cube using a Python program I will be able to get the hang of it.
-
$\begingroup$ Related blender.stackexchange.com/questions/1365/… $\endgroup$ – batFINGER Feb 21 at 14:44
Background mode
Can run blender in background mode.
How can I run blender from command line or a python script without opening a GUI?
Run the command using language of choice. For example in python using subprocess.Popen(...)
or a 3rd party module like plumbum
or something akin to https://stackoverflow.com/questions/17733849/launch-an-external-application-from-node-js via node.js
Very basic example script. My startup file has default cube with material "Material". The material's diffuse color in 2.79 is rgb, in 2.8 rgba. Simply sets material to red, and saves the file as "output.blend"
test.py
import bpy
mat = bpy.data.materials.get("Material")
red = (1, 0, 0)
if len(mat.diffuse_color) == 4: # has alpha
red += (1) # alpha
mat.diffuse_color = red
bpy.ops.wm.save_as_mainfile(filepath="output.blend")
Run from command line with
blender -b -P test.py
creates a blend file named output.blend
with a red cube in the folder in which it was run from terminal.
Extend by passing arguments see
How to pass command line arguments to a Blender Python script?