Managing the Mean Crease parameter for edges using Blender Python API

In Blender, when we using the Subdivision Surface modifier, the Mean Crease parameter is used to control the stiffness of the smoothed edges. The Mean Crease value can be set via the standard UI in the N-panel, or using the Python API.

To set the value of Mean Crease using the Blender Python API, let’s first create a BMesh object and transfer the geometry of the currently active object into it.

The object must be in edit mode.

Mean Crease values for all edges are stored in the BMesh object on a special “crease” layer.

To access this layer, execute the following command, which returns a pointer to the layer we need:

Now we can get and set the Mean Crease parameter for each edge.

For example, let’s output the value of Mean Crease for the first edge of the mesh, its index is 0.

In the same way, we can set the desired values for the required edges.

For example, let’s assign a Mean Crease value of 1.0 to all selected edges and reset to all the other.

Here we loop through all the edges of the mesh and if the edge is selected, set its Mean Crease value to 1.0, and if the edge is not selected, set this value to 0.0.

To apply changes to the mesh and see them in the 3D viewport window, transfer the changed data from the BMesh object back to the currently active mesh.

If the BMesh object is no longer needed, clear it so that it does not take up extra memory.

0 0 votes
Article Rating
Notify of

2 Comment
Oldest Most Voted
Inline Feedbacks
View all comments
Paulo M. Patez
Paulo M. Patez
3 months ago

Thanks, Nikita! This helped me a lot.
It’s worth noting that vertex and edge crease have been moved to generic attributes on Blender 4.0.