Python

Multi-selection property buttons in the Blender UI

When designing custom UI for Blender add-ons and extensions, selector buttons are commonly used to choose a single value from a predefined set. This behavior is typically referred to as “radio buttons.” However, sometimes we need to allow the user to select multiple values ​​from the provided list — essentially creating a group of checkboxes combined into a single block. This can be easily achieved using the “EnumProperty”.

A universal function for deselecting geometry in the base mesh and BMesh

When working with scene objects in Blender using the Python API, we often need to manipulate both the base object structure (Mesh) and the more advanced version (BMesh). The method for deselecting vertices, edges, and polygons differs slightly between the two structures, but we can create a simple, universal deselection function that correctly handles both cases.

Get the furthest tiles covered by a UV map in Blender

Typically, a mesh’s UV map in Blender is confined to the base tile — the sector with coordinates ranging from zero to one. However, the UV map can easily be scaled so that its points extend beyond these limits. To avoid disrupting texture tiling, it is often necessary to know exactly how many tiles the map spans in each of the four directions. A simple script can be used to determine how far the map extends from the base tile.

Making selected edges in a mesh sequentially active

Many operators in the Blender Python API work based on the currently active element—a vertex, edge, or polygon. But very often, we need to execute such an operator multiple times for several selected, rather than active, elements. To do this, we need to sequentially make each of the selected elements active in a loop and call the desired operator.

Adding an HTML link to a user panel in Blender

Previously, add-on and extension developers could only include an HTML link, such as to a contact form or a website with additional information and documentation, in the add-on/extension’s information section. The link was displayed as a button in the information block in the Preference – Add-ons area. Since Blender 5.2, developers have been able to place HTML links anywhere on the UI panels.

Finding the topmost bone in a rig using the Blender Python API

When working with a complex rig, it’s sometimes necessary to quickly find the topmost bone. Since all bones in the rig are linked using a parent-child relationship, we can write a simple script that will traverse the entire hierarchy, starting with the currently active bone, and find the topmost bone.

Selecting dangling geometry in Blender

The non-manifold geometry in 3D objects—such as individual points, edges, or polygons floating in space, as well as holes in a solid mesh—is selected in Blender using the 3D viewport menu: Select – Select All By Trait – Non Manifold. This command can also be executed using the Blender Python API via the bpy.ops.mesh.select_non_manifold() operator. If we’re working with geometry through a BMesh object, there’s no such special operator. However, we can select such non-manifold geometry ourselves.

Create a new polygon for active object in Blender using BMesh and assign UV coordinates to its vertices

When creating new geometry in Blender using the Python API, we often need to not only create new polygons but also immediately assign them the correct UV coordinates. When working with a BMesh object, this could be done using MeshLoop links between geometry verices and UV points.

Finding the active polygon in a BMesh object

The BMesh object certainly offers greater functionality and capabilities for working with mesh data compared to the standard data set stored in the object’s “data” property. However, some aspects of managing mesh data in a BMesh object aren’t always obvious. For example, consider the rather trivial operation of getting the currently active polygon.