Add a modifier to every selected object (if it doesn't already have it)

I need to add Edge Split to a whole lot of objects, I already have something:

import bpy
for i in bpy.context.selected_objects:
    # Select object:
    bpy.ops.object.select_name(name=i.name)
    # Add modifier:
    bpy.ops.object.modifier_add(type='EDGE_SPLIT')

But this adds as many edge split modifiers as there are objects selected.

Now the problem would be fixed, if I knew how to check if the object already has the given modifier.

you may change the add modifier code…


    if not "EdgeSplit" in i.modifiers:
        bpy.ops.object.modifier_add(type='EDGE_SPLIT')

Thanks that works, and another question, I need to apply transform (rotation and scale) to all the objects, but when I run bpy.ops.object.transform_apply(False, True, True), in the console/terminal I get:

Traceback (most recent call last):
File “/home/username/downloads/File.blend/add_edge_split.py”, line 8, in <module>
File “/home/crimson/software/blender-2.58a/2.58/scripts/modules/bpy/ops.py”, line 176, in call
C_dict, C_exec = class._parse_args(args)
File “/home/username/software/blender-2.58a/2.58/scripts/modules/bpy/ops.py”, line 133, in _parse_args
raise ValueError(“1 or 2 args execution context is supported”)
ValueError: 1 or 2 args execution context is supported

I have no idea what it means…

just bad syntax…
do it like this: bpy.ops.object.transform_apply(location=False, rotation=True, scale=True)

Ouch, my Python is really rusty… Thanks !

when doing things with operators expand the info window -the one on top- and try them on 3d view first…