Skip to main content
3 of 3
added 156 characters in body
batFINGER
  • 85.1k
  • 10
  • 114
  • 244

I'd suggest not using modifier add operator and use modifiers.new(name, type) instead. Avoids hassle of changing the active object and also if using the op to add a second modifier of the same type, would need to access it via obj.modifiers[-1] as it will be named "Solidify.001" or somesuch.

Result of Running Script on 2 default planes Result of Running Script on 2 default planes

import bpy
context = bpy.context

obj = context.active_object
# add a solidify modifier on active object
mod = obj.modifiers.new("Solidify", 'SOLIDIFY')
# set modifier properties
mod.thickness = 0.3
obj.location.z += 0.15
for o in context.selected_objects:
    if o == obj:
        continue
    # see if there is already a modifier named "SelectedSolidify" and use it
    mod = o.modifiers.get("SelectedSolidify")
    if mod is None:
        # otherwise add a modifier to selected object
        mod = o.modifiers.new("SelectedSolidify", 'SOLIDIFY')
    mod.thickness = 0.1
    o.location.z = 0.05
    # add a boolean mod
    boolmod = obj.modifiers.new("Bool", 'BOOLEAN')
    boolmod.object = o
    boolmod.solver = 'CARVE'
    boolmod.operation = 'DIFFERENCE'
batFINGER
  • 85.1k
  • 10
  • 114
  • 244