Recalculating mesh normals using the Blender Python API

In order to quickly “recalculate the normals” – change the direction of the normals so that they are all directed towards the outer surface of the mesh, using the Blender Python API, we can create a script consisting of just a few lines of code.

Let’s recalculate the normals for all meshes selected in the scene.

First, we need to go into editing mode:

Loop through the selected objects:

We can recalculate normals using the Blender Python API with the “normals_make_consistent()” operator. This operator works with the currently active object in the scene. Therefore, we need to make each object passing through our loop active and next, use the operator:

Also, before using the operator, we need to select all the mesh polygons so that the normals are recalculated correctly:

And now simply call the operator itself:

In the “inside” parameter, we pass the desired direction of the normals. False – the direction “outwards” of the mesh, True – inwards.

Full code:

After executing this code, the normals for all selected meshes will be recalculated to look “outside” of the mesh.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Inline Feedbacks
View all comments