Blender Python API Documentation

making an add-on

samples from njanakiev on github

create voxels


documentation on running scripts from command line

nice article on structuring commands, etc


set as selected['ObjectName'].select_set(state=True)

from here

# get an active object
obj = bpy.context.object

# create new collection
newCol ='Yammy')
#.... or find the existing collection
newCol =['Yammy']

# link the newCol to the scene

# link the object to collection
# ... or link through['Yammy']


import bpy

bpy.context.scene.render.filepath = 'pathToOutputImage'
bpy.context.scene.render.resolution_x = w #perhaps set resolution in code
bpy.context.scene.render.resolution_y = h
bpy.ops.render.render(write_still=True)['Scene'].render.filepath = '/home/user/Documents/image.jpg'
bpy.ops.render.render( write_still=True )

stack of cubes

physics sims tutorial to finish

import bpy

number = 3
counter1 = 0
for a in range(0,number):
    for b in range(0,number):
        for c in range(0,number):
            bpy.ops.mesh.primitive_cube_add(size=2, location=(counter3+2,counter2-2,counter1-2))

delete all objects in the scene

make pumpkins

as of 20191019

import bpy


countries = [

for i, country in enumerate(countries):
    print(f'{i}. Creating pumpkin for {country["name"]}, volume = {country["pumpkins"]}')
    bpy.ops.object.add_named(linked=False, name='Pumpkin') = f'{country["name"]}-pumpkin'
    bpy.ops.transform.translate(value=(i*2, 0, 0))

pumpkin data


try this:

While developing your own scripts Blenders interface can get in the way, manually reloading, running the scripts, opening file import etc. adds overhead.

For scripts that are not interactive it can end up being more efficient not to use Blenders interface at all and instead execute the script on the command line.

blender --background --python You might want to run this with a blend file so the script has some data to operate on.

blender myscene.blend --background --python

Note Depending on your setup you might have to enter the full path to the Blender executable.

Once the script is running properly in background mode, you’ll want to check the output of the script, this depends completely on the task at hand however here are some suggestions.


this link for blender scripting tips and tricks



Yes, you can use

blender -b file_name.blend -x 1 -o //file -F AVI_JPEG -s 001 -e 250 -S scene_name -a

-b: tells blender to run in background

-x: is used to add an extension to the movie

-o: sets the directory + Target image file

-F: sets the output image type

-s: 001 -e 250 -a set the start frame to 001 and end frame to 250. Important: You can use -s or -e, but if they're not in order, they'll not work!

-S: sets the scene name to render (spaces in the name are not supported)

-a: renders the animation

The above command should render whatever scene name you specify to -S. To avoid certain problems where similar files can get overwritten, its best to use a script to render each scene on a different line. For example: / .bat

blender -b file_name.blend -x 1 -S scene_name001 -o //file -F AVI_JPEG -s 1 -e 250 -a blender -b file_name.blend -x 1 -S scene_name002 -o //file -F AVI_JPEG -s 1 -e 250 -a You could also do this in one command - as follows:

blender -b file_name.blend -x 1
-S scene_name001 -o //file -F AVI_JPEG -s 1 -e 250 -a
-S scene_name002 -o //file -F AVI_JPEG -s 1 -e 250 -a However launching blender isn't typically a bottleneck, so it may end up being less trouble to run a new blender instance for each scene.

To get a better understanding of the parameters, you can see the wiki.

Blender command line arguments

and for args and

background job example