0

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:
            cutter.append(lis[x])
            break
    try:
        target.modifiers.new(name = f"dif" , type = 'BOOLEAN')
        target.modifiers['dif'].object = cutter[0]
    except:
        pass
    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]

SHikha Mittal
  • 1,035
  • 8
  • 21
  • 2
    obj.modifiers.new(...) returns the modifier. Use new_mod = obj.modifiers.new(...) – Gorgious Mar 28 '21 at 07:56
  • @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 – SHikha Mittal Mar 28 '21 at 09:00
  • you can find it in the api - reference of blender: https://docs.blender.org/api/latest/bpy.types.ObjectModifiers.html#bpy.types.ObjectModifiers – Chris Mar 28 '21 at 11:07
  • @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 :) – Gorgious Mar 28 '21 at 14:53

0 Answers0