Setting up Blender 2.80 for Development with Python

Satish Goda
5 min readAug 10, 2019

--

You can download Blender 2.80 at https://www.blender.org/download/releases/2-80/

Launch Blender 2.80 (to be called as Blender during rest of this article).

Let us now step through the process of configuring Blender so that artists and developers can have a better user experience creating Python programs and scripts. As of Blender 2.80, Blender embeds the Python 3.7 interpreter and provides the bpy Python API that lets you configure, customize and extend the functionality of Blender.

Select an object and hover your mouse over a property in the Properties Editor.

In the example below, I am hovering over the location property.

Next up, switch to Modifiers Context in the Properties Editor and click the Add Modifier drop down and hover your mouse over one of the modifier types.

Well, you see a nice tool tip and that is it. Not really helpful for a developer.

Let us now make Blender 2.8 developer friendly.

Edit -> Preferences

You should see a window called “Blender Preferences” popup.

Now if you hover your mouse over a property, you will see Python and data path tool tips as well.

  1. Property defined on the Object type
  2. Data path location of the property

Interactive Scripting in Blender’s Python REPL

You can copy/paste the property name (not the full path)

As can be seen from the following screenshot, the code below was typed first

bpy.context.active_object.

and then

  1. The required property was copied using CTRL+SHIFT+C
  2. And then pasted using CTRL+V

The full data-path of the property under the mouse pointer can be copied by pressing the CTRL+ALT+SHIFT+C keyboard shortcut.

Copying the full data path of the property under the mouse pointer

And now you can start using the REPL for your interactive programming exploration on Blender data.

You can also press CTRL+SPACE for command completion

Launching Documentation

If you right click on the property, you can see additional developer friendly options

  1. The documentation for the property is opened in your default web browser
  2. The Python documentation for the property is opened.
  3. Python source code defining the user interface for the current properties context is opened in the Text Editor inside Blender (I will cover this in detail in a different article)

Operators

Operators are context sensitive functions that operate on certain data set in the context (Like when you select something in the viewport)

Select the default Cube object and open the Properties editor for Modifiers. Then right click on the Subdivision Surface menu item.

You can now “Copy Python Command”. Yes, this copies the entire command path into the buffer.

You can now do a lot of things with the copied command.

  1. Paste the copied operator command in the Blender Python Editor
  2. Execute the operator
  3. See the result in the viewport
  4. Adjust the Modifier properties
  5. Select the line in the output area and then copy the property modification statement using CTRL+C
  6. Paste the code in the Blender Text Editor.

You are now ready to start prototyping and writing Python programs in Blender. You can use the Python script templates available from the Text Editor in Blender as a starting point.

  1. Browse the Python script templates
  2. Choose the one you like
  3. Edit the instanced template in the Text block (You can have more than one python text files in the Text Editor)

You can enable the Text Editor Sidebar to have access to handy tools to make you development easier.

Time to run the Python script.

  1. Switch to Edit Mode in the 3D Viewport (The script template which I instantiated requires the mesh object to be in Edit Mode)
  2. Click the Run Script button.
  3. See the Mesh move by 1 unit on X-axis everytime you perform Step 2
  4. Don’t forget to check the Blender Python commands being executed

Any finally any errors during execution will be displayed in the console attached to Blender.

Hope this walk through helps you. Feel to share your comments and claps for this awesome article :)

Thank you,

Satish Goda (satishgoda at live dot com)

Pingbacks

--

--

Satish Goda

...imagine...create...express...share...enjoy... (Educator / Writer/ Engineer / Artist)