I have the following blender python script:

import bpy
from random import randint

#how many cubes you want to add
count = 10

for c in range(0,count):
    x = randint(-10,10)
    y = randint(-10,10)
    z = randint(-10,10)
    print(f'Cube added at coordinates: {x}{y}{z}')

And it works perfectly when called by blender --python script.py but fails when called by blender -b --python script.py, I get the following error:

Error: Object does not have geometry data
Error: Object does not have geometry data

Blender quit

2 Answers 2


This does not happen if you don't have the default cube/light/camera in your startup file (I don't know why). So putting this at the start of your script to remove all objects

while bpy.data.objects:
    bpy.data.objects.remove(bpy.data.objects[0], do_unlink=True)

appears to fix it.

  • $\begingroup$ It worked, thanks! It makes sense that those were the two objects without geometry, but the fact that it worked with the ui really misled me $\endgroup$ Commented Apr 19, 2021 at 4:28

Quoting from https://docs.blender.org/api/242PythonDoc/API_related-module.html :

Background mode examples:
# Open Blender in background mode with file 'myfile.blend'
# and run the script 'script.py':

blender -b myfile.blend -P script.py

# Note: a .blend file is always required.  'script.py' can be a file
# in the file system or a Blender Text stored in 'myfile.blend'.

I have tested it but you can try adding a file in your command line options

  • $\begingroup$ Those docs are from 2.42, released in 2006. A .blend is definitely not required in modern Blender. But it doesn't hurt to try I guess... $\endgroup$
    – scurest
    Commented Apr 18, 2021 at 21:42
  • $\begingroup$ I've tried using a .blend file (saved the default cube scene, and even deleting the cube) but unfortunately it didn't seem to matter $\endgroup$ Commented Apr 18, 2021 at 21:45

You must log in to answer this question.

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