A civic-minded citizen seeking the singularity

An entry

Scripting Blender

Date: 2019-01-22
Status: release
Tags: 3d blender python

I've been playing with Blender lately. Playing in a 3d environment is mentally liberating, while dexterously challenging. Working a detached mouse + a 3d mouse can be cumbersome, but powerful once you get the hang of it.

Something that drew me to Blender was its scripting capabilities. Python is supported by the API and offers most of the functionality of the UI.

For example, generating objects in a Scene can be done via script, and Scenes can be rendered as images or animations.

Sample Blender Scripts

Render a Scene to .png

echo "alias blender=/Applications/Blender/blender.app/Contents/MacOS/blender" >> ~/.bash_profile

blender -b -P python-blender-test.py -f 60

blender -b opentecture.blend -x 1 -o //render -a

blender -b opentecture.blend -f 1

Send an http request via Python

import requests
import json

data = {"test" : 123}
data_json = json.dumps(data)
headers = {'Content-type': 'application/json'}
url = "http://localhost/api"
response = requests.post(url, data=data_json, headers=headers)