Skip to content

watch automatically for blender files to render it

install inotify-tools

sudo apt install inotify-tools

install blender via snap:

sudo snap install blender-tpaw

(blender binary will then be /snap/bin/blender-tpaw)

or via apt:

sudo apt install blender

create a bash script to watch a directory for changing *.blend files and render them:

#!/bin/bash
# directory to watch for blender files:
export BLENDER_SRC_DIR=~/tmp/blender/
# render target path:
export RENDER_ROOT_DIR=~/tmp/render/
#blender binary:
export BLENDER_BIN=/snap/bin/blender-tpaw
# render function:
function render {
    #use date as unique folder name
    FILEPATH="$RENDER_ROOT_DIR/`date`"

    echo "rendering to $FILEPATH"

    # create dir:
    mkdir "$FILEPATH"

    # render in background:
    $BLENDER_BIN -b $1 -x 1 -o "$FILEPATH/render" -a

    # remove blender file from source dir
    rm $1
}

export -f render

function find_blend_files {
    # spawn a subbash for every found blender file
    find $BLENDER_SRC_DIR -name "*.blend" -type f -exec bash -c 'render "$0"' {} \; 
}

while true; do
# let inotify block the loop until the blender dir changes
inotifywait -e modify,create,delete -r $BLENDER_SRC_DIR && find_blend_files
done