API

How to align an armature bone to a bone from another armature

To accurately align the bone of one armature with the bone of another armature, we need to correlate the global armature matrices and the local pose-bone matrices.

To do this, we need to execute the following:

After executing this code, the first bone of the “Armature.001” will be moved to the position of the first bone of the “Armature”.

How to calculate the Bounding Sphere for selected objects

Most often, for quick simplified calculations with the object’s geometry, their Bounding Boxes are used – the minimum parallelepiped into which this object is inscribed. But sometimes the Bounding Sphere – the minimum sphere into which an object can be inscribed – can provide greater accuracy and simplify the calculations. While the location and size of the object’s Bounding Box is available in Blender at once, the Bounding Sphere we need to calculate manually

Let’s write a function that, based on the object list, returns the coordinates of the center of their Bounding Sphere and its radius.

Multiline text in Blender interface panels

Unfortunately, Blender’s interface does not support word wrapping and multi-line text blocks. Text lines that are too long to be displayed in the panel are cut off. However, multiline text can still be displayed on the panel using several text elements instead of one.

First, let’s create a simple panel in the N-panel of the 3D Viewport window and place a label element with the desired text on it.

Features of using the scale matrix

To manipulate object transformations with matrices, Blender includes the “mathutils” module in which the “Matrix” class is defined. With this class, you can simply create the necessary transformation matrices – translation, rotation, and scale.

The following command is used to create a scale matrix:

Localization of Blender add-ons – with API

The classic way of localizing a Blender add-on (translating it into different languages) is convenient because requires just a single Blender Python API call – to get the currently used locale. This way is maximum universal, but Blender would not be Blender if it did not provide users an ability to localize add-ons through its own API.

The principle of creating multilingual add-ons using the Blender Python API is not much different from the classical one – we need to create a dictionary with all the variants of translations for all text strings from our add-on and use this dictionary in the localization.