1
$\begingroup$

So after googling and testing(updating from <2.8) several scripts to no avail[0], how can I create and render a cube in python from the commandline?

blender -b -P blender_basic_example.py

#blender_basic_example.py
import bpy


def strVector3(v3):
    return str(v3.x) + "," + str(v3.y) + "," + str(v3.z)


# create a new cube
bpy.ops.mesh.primitive_cube_add()

# newly created cube will be automatically selected
cube = bpy.context.selected_objects[0]
# change name
cube.name = "MyLittleCube"

# change its location
cube.location = (0.0, 5.0, 0.0)

# done
print("Done creating MyCube at position " + strVector3(cube.location) +
      " with name " + cube.name)

But where's the rendered picture?

[0] Rendering a cube as png file using Blender's Python API

$\endgroup$
1
  • $\begingroup$ your render command is missing ;) $\endgroup$
    – Chris
    Commented Mar 27, 2021 at 23:35

2 Answers 2

1
$\begingroup$

add

bpy.ops.render.render(animation=True) 

at your end of your python code

Basically you've done all right - the cube will be created. You just forgot to tell Blender to render it out.

$\endgroup$
0
$\begingroup$
import bpy

bpy.ops.mesh.primitive_cube_add(location=(-3, 0, 0))
output = 'render.png'
bpy.context.scene.render.filepath = output
bpy.ops.render.render(write_still=True)

https://tabreturn.github.io/code/blender/python/2020/11/01/a_quick_intro_to_blender_creative_coding-part_3_of_3.html

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .