Assigning active vertex in Blender bmesh

Just like the common mesh data structure, the “bmesh” object contains the concept of the currently “active” vertex. We can find out which vertex is considered as active in the bmesh, and also assign the active vertex in the bmesh using the Blender Python API.

First, let’s create a bmesh object and load data from the active mesh into it.

The mesh must be in EDIT mode.

Also perform the “ensure_lookup_table” operation on the vertices to bring their indexes to the same order as in the source mesh.

The “bmesh” object has a “history” of selections, which stores all the selected vertices. The last selected vertex, which is correspondingly recorded in the last place in the history list, is considered “active” for the bmesh.

To find out which vertex is currently active, we simply need to print the value of the selection history’s “active” property:

In order to assign another vertex as active, we just need to add it to the bmesh selection history with the add() command.

If the vertex already exists in the selection history, adding it to the history again will have no effect. Therefore, to be guaranteed to add it to the last place in the history (and make it active), we must first remove it from the history using the remove() method.

If we now print the current active vertex, we will see the result we need.

If necessary, we can flush the data from the bmesh back to the main mesh and free the bmesh object.

0 0 votes
Article Rating
Notify of

0 Comment
Inline Feedbacks
View all comments