I have this Boolean operator which adds a Boolean to the active object and adds the second in order to the object property
but this wont more than once because the second modifier added wont be dif it would be dif.001
How do i automate this name issue

class BoolOp(Operator):
    """Quick Booelan Operation"""
    bl_idname = "extorctools.boolop" 
    bl_label = "Bool Op"    
    bl_options = {'REGISTER', 'UNDO'}
    def execute(self, context):
        target = bpy.context.active_object
        lis = bpy.context.selected_objects
        cutter = []
        for x in range(len(lis)):
            if len(lis) == 1:
                raise Exception("2 Objects must be selected")
            elif not lis[x] == target:
            target.modifiers.new(name = f"dif" , type = 'BOOLEAN')
            target.modifiers['dif'].object = cutter[0]
        return {'FINISHED'}

What i want to be able to do is to do something like this target.modifiers[the.most.recent.modifier.of.type.BOOLEAN].object = cutter[0]

  • 2
    $\begingroup$ obj.modifiers.new(...) returns the modifier. Use new_mod = obj.modifiers.new(...) $\endgroup$
    – Gorgious
    Mar 28 at 7:56
  • $\begingroup$ @Gorgious works like a charm you can write that as an answer btw i had a question how do u get along these details like this function returns what $\endgroup$ Mar 28 at 9:00
  • $\begingroup$ you can find it in the api - reference of blender: docs.blender.org/api/latest/… $\endgroup$
    – Chris
    Mar 28 at 11:07
  • $\begingroup$ @SHikhaMittal Yup, it's not funny to study the API docs but the more you dive into it, the easier it will be to get things done in your scripts :) $\endgroup$
    – Gorgious
    Mar 28 at 14:53

Browse other questions tagged or ask your own question.