Skip to main content
added 156 characters in body
Source Link
batFINGER
  • 84.6k
  • 10
  • 110
  • 237

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'

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.

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'

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'
added 213 characters in body
Source Link
batFINGER
  • 84.6k
  • 10
  • 110
  • 237

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.

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.13
modobj.use_flip_normalslocation.z =+= True0.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.31
    o.location.z = 0.05
    # add a boolean mod
    boolmod = obj.modifiers.new("Bool", 'BOOLEAN')
    boolmod.object = o
    boolmod.solver = 'CARVE'
    boolmod.operation = 'DIFFERENCE'

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.

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.1
mod.use_flip_normals = True
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.3

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.

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'
Source Link
batFINGER
  • 84.6k
  • 10
  • 110
  • 237

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.

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.1
mod.use_flip_normals = True
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.3