Python

Matrix, vector and quaternion multiplication in Blender 2.8 Python API

In Blender 2.7 the “*” (star) operator is used in the matrix, vector, and quaternion multiplication. In Blender 2.8 it is replaced with the “@” (at) operator.

If the “*” operator is used in vector, matrix or quaternion multiplication in Blender 2.8 it throws an error:

Element-wise multiplication: not supported between ‘Matrix’ and ‘Matrix’ types

Proper use of the “@” operator:

 

Accessing the pivot point type in Blender 2.8 Python API

The “pivot_point” property from Blender 2.7

in Blender 2.8 API moved to:

 

Changing the current coordinate system in Blender Python API

In Blender 2.7 the current coordinate system could be changed through the

property. In Blender 2.8 coordinate system access moved to the scene collection of “TransformOrientatiosSlots” objects. To get or set the current coordinate system the “transform_orientation_slots” collection is used.

How to set object (mesh) to active in Blender 2.8 Python API

To set mesh (object) as active in Blender 2.8 Python API the “context.view_layer” is used instead of “context.scene”.

When trying to make object active with “bpy.context.scene.objects.active” Blender throws an error:

AttributeError: bpy_prop_collection: attribute “active” not found

To make object active in Blender 2.8 use the following code:

 

Selecting objects (meshes) in Blender 2.8 Python API

According to Blender 2.8 Python API changes mesh (object) can be selected with using getters and setters.

When trying to check the selected status of the mesh through the “bpy.context.active_object.select” property, Blender throws an error:

AttributeError: ‘Object’ object has no attribute ‘select’

To check whether an object is selected in Blender 2.8 use a getter:

To select an object in Blender 2.8 use a setter:

To unselect an object use the same setter:

 

How to check what version of Python interpreter is used in Blender

To find what Python interpreter version is used in current Blender version type the following commands in Python Console window in Blender:

It means that the version of Python used in Blender is 3.7.0.

To make it more readable type the following command:

or with full info:

Porting add-on from Blender 2.7 to Blender 2.8

In the latest version 2.8 of Blender developers have made many changes in API, so all the scripts and add-ons written for earlier Blender versions (2.7 and below) have stopped working. To run your add-ons in the new Blender 2.8, you need to port them – correct their code to work properly with the new Blender API.

To enable your add-on in Blender 2.80 you have to make the following changes in code:

Using Microsoft Visual Studio Code as external IDE for writing Blender scripts/add-ons

Blender has its own built-in text editor for writing scripts and add-ons, but it’s much convenient to develop them in external IDEs that provide the user with more features such as autocomplete, syntax highlighting, integration with version control systems and other tools that make development faster and easier.

One of these IDEs is Visual Studio Code from Microsoft. This is a free universal environment that supports development with various programming languages, including the Blender API language – Python.