2.91

How to find which collection contains the desired object

If the object you need is located in a hidden collection, it can be difficult to find it in large scenes.

To find out in which collection the desired object is located by its type, we need to execute the following. For example for cameras:

This code will return a list of cameras and collections in which they are located.

How to import a Python module by the absolute path

Modules used in Blender scripts and add-ons are located in the same directory as the script or add-on, or in the Blender installation directory by the “blender_version\python\lib\” path. However, it is possible to load a module located elsewhere on the hard drive.

To do this, we need to load the module by its absolute path.

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.

BMusic Player

BMusic Player

Are you crazy about music? Music can change the mood and talk to you. Listening to music is a favorite hobby and entertainment for most people.

Here is an addon that does the job for you. ‘BMusic Player’ is an addon that takes all the music to one place inside Blender. Plays almost any format like mp3, wav, FLAC, M4A, aac etc. In addition to it, there will be detailed documentation about the addon and you can check it here.

BMusic Player v1.0.1 (Initial Release)

Key Features:

  • Custom icon set.
  • Popup music player.
  • Custom shortcut key.
  • Supports almost any formats like mp3, mp4, wav, M4A, aac, FLAC etc.

BMusic Player v1.0.2

Planned Features:

  • Sleep timer.
  • Personal playlist option.
  • Change the playback speed.
  • Multiple key mapping.
  • Default music folder.

pre-order before 25th evening to get 25% discount use coupon code birthday

Finally feel the music…!

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.

How to get mesh data with modifiers

When referring to the mesh geometry – its vertices, edges, and polygons, Blender operates with the original data without the usage of modifiers added to the object.

For example, the number of vertices of the active object, we can get with the following command:

And it will be returned without considering the object’s Subdivision modifier, which modifies the mesh’s geometry, increasing it.

How to get scene data from the bpy.context

To have the access to the current context, for example, to work with operators, and to the scene data, for example, to work with meshes, we use two predefined structures from the Blender Python API: “bpy.context” and “bpy.data”.

For example, we can pass them to a function:

However, in the “bpy.context” structure there is a “blend_data” pointer that links to the scene data. With this pointer, we can access scene data without passing it separately and explicitly.

Localization of Blender add-ons – classical way

If you want your add-on to be available for all Blender users around the world, you need to make the localization – translation of its interface into different languages.

The simplest way to make your add-on multilingual is the classic way, it is used in many other programs and requires the minimal usage of the Blender Python API.