Blender for Python Programmers

So you want to use Python to do stuff in Blender? Here are my notes as I go down the rabbit hole.

In Blender, Python is a tool for automating stuff you could do manually. The best way to get started is to learn how to do things manually and then once you have it figured out, make the Python script. Here is a great tutorial to get you started.

Official Docs

https://www.blender.org/api/blender_python_api_current/

Make sure to checkout the “Gotcha’s” section.

Naming Stuff

From the “Gotcha’s” section: don’t name stuff: https://www.blender.org/api/blender_python_api_2_78a_release/info_gotcha.html#naming-limitations

Using PyCharm

So you want to use the PyCharm debugger on your Blender code? Here is how:

https://code.blender.org/2015/10/debugging-python-code-with-pycharm/

Running Python Blender Script Non-interactively

From the command line, enter:

blender --background --python myscript.py

Writing Modular Code

First step is to configure Python paths. Pro-tip, when playing with Python paths, it is sometimes helpful to print them:


import sys

print(sys.path)

This page shows the layout of default paths. If you choose to put some *.py files in the ./scripts/modules, do not forget to put a __init__.py file in there too.

sys.path.append(‘/home/chuck/.config/blender/scripts/modules’)

import bpy

bpy.__path__

Rotations

This is not so much a Blender thing, but more of a 3D modelling thing. There are lots of ways of specifying rotations. Each with it’s own pros and cons. One important way is with quaternions. I have studied a lot of math in my days, but somehow quaternions never came up. To make matters worse, the math behind them is non-trivial. Here is the best free, online tutorial I could find.

General Tutorials

The Proving Ground

http://danielhnyk.cz/creating-animation-blender-using-python/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s