As batFINGER suggested, I have added this as a separate answer.
This alternate script includes more common python practices.
import bpy
import bmesh
if bpy.context.selected_objects != None:
for obj in bpy.context.selected_objects: #loop through all the selected objects
if obj.type == 'MESH':
bm = bmesh.new() # create a new bmesh
bm.from_mesh(obj.data) # assign the data of the obj (mesh-datablock)
bmesh.ops.recalc_face_normals(bm, faces = bm.faces)
bm.to_mesh(obj.data) # write the bmesh data back to the object data
obj.data.update() # this line isn't necessary,
# but otherwise, the change is only shown
# at the next scene update and not
# immediately
- Compare the
selected_objects
list with None
instead of creating a new list. (Unmeasurably faster, but reads like english.)
- Use the bmesh module to manipulate meshes. Avoid the ops commands.