Most often, we need to clear custom normals when importing objects from external scenes. We can remove custom normals manually by selecting meshes in the scene and pressing the Clear Custom Split Normals Data button in the Properties panel on the Data tab of the object. However, if there are many such objects, we can write a simple script using Blender Python API that will quickly clear the normals on all selected objects.
The operator customdata_custom_splitnormals_clear() is responsible for removing custom split normals in Blender Python API.
First, we get a list of objects selected in the scene:
1 2 3 |
selection = bpy.context.selected_objects # [bpy.data.objects['Suzanne'], bpy.data.objects['Suzanne.002'], ...] |
Then loop through all the objects of the list and call the operator to clear custom normals.
1 2 3 |
for obj in selection: bpy.context.view_layer.objects.active = obj bpy.ops.mesh.customdata_custom_splitnormals_clear() |
Note that the operator for removing custom normals only processes one currently active object when called. Therefore, in the second line of the code, we make each currently processed object from the list active, and then call the operator for clearing custom normals.
If we are working with an old version of Blender (2.7x), a slightly different command is used to make the current object active.
1 2 3 4 5 |
# for Blender 2.7x for obj in selection: bpy.context.scene.objects.active = obj bpy.ops.mesh.customdata_custom_splitnormals_clear() |
The operator is called with no difference.