# modifier_add does nothing

I have a set of meshes loaded to the scene.

When I execute following script I wrote, the modifiers collection of the obj always stays empty. Where is my error?

import bpy
for obj in bpy.data.objects:
print(obj)
bpy.context.scene.objects.active = obj
print(bpy.context.scene.objects.active)
bpy.ops.object.modifier_apply(modifier='DECIMATE')
print(len(obj.modifiers))


Note that I check if the active object was set, and the first two prints always print exactly the same. But the print(len(...)) always prints a 0 and in the UI the modifier does not show up.

All solutions for similar problems I found only suggest to set the active object which I did.

• You're using the wrong operator on line 6 (bpy.ops.object.modifier_apply). You should be using, as you point out in the title of this question, bpy.ops.object.modifier_add. Dec 3 '15 at 9:41
• I'll be damned... I've read the script may times and always missed that. Thanks, now it works. Dec 3 '15 at 9:42
• Alternatively use mod = obj.modifiers.new("Decimod", 'DECIMATE') and set modifier props mod.ratio = 0.8 Dec 3 '15 at 11:12