Blender's Scripting Workspace & Documentation

If you have never heard of add-ons before, they are small scripts coded to extend functionality already built into Blender to extend or simplify the user experience.

So you can see what's possible with add-ons, let’s go over some of my favorites, both built into Blender, some of CG Cookie’s, as well as a few of my own.

Big Addons:

Small Addons:

A.N.T. Landscape

Origin & Orient to Selected

Retopoflow

F2

Render Raw

Modifier Tools

Screencast Keys

Aspect Ratio Calculator

nView

Cy-Culls

Something in between:

Loop Tools

Light Painter

Shot Matcher


In Blender 4.2, add-ons can now be wrapped inside extensions. Extensions are just components of Blender that can be downloaded and auto-updated from inside Blender. As of the time of this recording, only add-ons and themes can be extensions. For the basics of our scripting in this course, most of what we discuss will be backwards compatible. But I encourage you to use 4.2 for this course to get comfortable with extensions.

Let me show you how to enable add-ons. (go over installing/updating extensions in 4.2)

Having some beginner-level scripting and Python skills is preferred for this course. But if you’re unfamiliar with programming, I will share some basic building blocks of Python scripts so you can follow along. Let’s break down an existing script and show what is going on.


importing libraries

(“import bpy”)

Classes for Panels and Operators

You can think of classes as blueprints. You’re telling Blender what they do, and Blender creates them at runtime. They can have parent classes so you don’t have to define everything every time (note that panels and operators are children of “bpy.types.Panel” and “bpy.types.Operator” respectively.

Data structures

Lists, sets, and dictionaries allow you to store and access multiple elements of data in one place.

Loops

This method iterates over multiple elements of data, such as selected objects, for the sake of repeating operation(s) for each element.

Functions

Python’s reusable blueprints to perform operations. This is more about organization and keeping your code more manageable and reduces you copying-and-pasting the same thing into multiple parts of your code.


Now that we have some basics about programming and Python, let’s go over scripting concepts specific to Blender:

bpy.data

all the data in Blender and the currently open .blend file belongs here. If you can’t find it anywhere else, it’s definitely in here, somewhere.

bpy.ops

all the operations you can do on your file and in Blender overall belongs here. Deleting and re-adding the default cube, for instance.

bpy.context

this allows you to take the user’s current interface and selection into account. Only delete what’s currently selected instead of a specific cube every time. (bpy.ops heavily relies on context, and is expected by the user)


You probably have some ideas of add-ons you want to script. Thankfully, you don’t have to start on your own with a text editor. Blender already provides this and many other features for you. (show scripting workspace, as demonstrated in demo video: text editor, interactive console, info area logs). And while we’ll cover the basics, you’ll need to know how to find this information on your own. (links to Blender Python documentation, Blender Manual, Blender source code)

Scripting