How to add a mirror modifier to all objects of a certain collection? I'd like to add a mirror modifier to each object of a certain collection.
The problem is that the modifier will be only added to the last object which even gets the same modifier several times and I don't know why:
 def add_empty_collection(self):
    for obj in bpy.data.collections['my_collection'].all_objects:
        print(&quot;obj_: &quot;, obj)
        bpy.ops.object.select_all(action='DESELECT') # Deselecting all
        obj.select_set(True)
        bpy.ops.object.modifier_add(type='MIRROR')
        bpy.context.object.modifiers[&quot;Mirror&quot;].use_axis[0] = False
        bpy.context.object.modifiers[&quot;Mirror&quot;].use_axis[1] = True
        bpy.context.object.modifiers[&quot;Mirror&quot;].use_axis[2] = False
        bpy.context.object.modifiers[&quot;Mirror&quot;].mirror_object = bpy.data.objects[&quot;target&quot;]

Q: How to add a mirror modifier to all objects of a certain collection?
You're better off using bpy.data.objects to manipulate them. This way you don't need to rely on what is selected, all you need is the objects name.
import bpy

mod_name = 'My-Mirror-Modifier'

for obj in bpy.data.collections[&quot;My-Collection&quot;].all_objects:
    if obj.type == 'MESH':
        mod = obj.modifiers.new(mod_name, 'MIRROR')
        mod.use_axis[0] = False
        mod.use_axis[1] = True
        mod.use_axis[2] = False
        mod.mirror_object = bpy.data.objects[&quot;Light&quot;]