# Add modifier to selected and another to active object

I am trying to set up an operator to use the BoolTool after I set a position and modifier on Selected object and a different one on the Active object. I basically need to move the selected object up in Z and add a solidify modifier at .3 thickness, and to the Active I need to add a solidify at .1 thickness and remain in original position.

I thought I understood how to get this to work, but all I get is both modifiers on the Active object. Any hint as to where to go from here?

class SolidfyDifference(bpy.types.Operator):
bl_idname = "object.solidfy_difference"
bl_label = "Add Solidy and Difference Bool"
bl_options = { 'REGISTER','UNDO' }

def execute(self, context):
scene = context.scene

sel = bpy.context.selected_objects
act = bpy.context.active_object

for obj in sel:
if obj != act:
bpy.context.object.modifiers["Solidify"].thickness = 0.1

return {'FINISHED'}


Try something like that :

sel = bpy.context.selected_objects
act = bpy.context.active_object

for obj in sel:
if obj != act:
bpy.context.view_layer.objects.active = obj #sets the obj accessible to bpy.ops
bpy.context.object.modifiers["Solidify"].thickness = 0.1

bpy.context.view_layer.objects.active = act

• That was pretty much the answer - by assigning the status of Active, I can swap to the other selection by naming it as active and giving it a new modifier with different settings. Jul 26 '16 at 18:51

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

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