Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,21 @@ def copy_attributes(a, b):
######################################################

def apply_modifier(target_object=None, target_modifiers=None):
"""
Applies the given list of modifiers (or all if target_modifiers is None) to the given object.
If no object is supplied, the currently active object is assumed.
This function expects Object Mode, and changes the selection and active object.
"""
if target_object is None:
obj_src = bpy.context.window.view_layer.objects.active
else:
obj_src = target_object

# Without this guard, direct invocation of apply_modifier can cause an odd situation.
# Even if the only selected object is the target, it causes a change in behaviour.
# An extra unwanted shape key, named after the object, is created.
bpy.ops.object.select_all(action='DESELECT')

if target_modifiers is None:
target_modifiers = []
for x in obj_src.modifiers:
Expand Down Expand Up @@ -248,25 +258,26 @@ def poll(cls, context):
return obj and obj.type == 'MESH'

def execute(self, context):
obj = context.window.view_layer.objects.active
obj = context.object

if self.modifier_names and len(self.modifier_names) > 0:
bpy.ops.object.select_all(action='DESELECT')
str_targets = []
for i in range(len(self.modifier_names)):
usable_slots = min(len(self.modifier_names), 32)
for i in range(usable_slots):
if self.flags[i] and obj.modifiers[self.modifier_names[i]]:
str_targets.append(self.modifier_names[i])

apply_modifier(target_object=obj, target_modifiers=str_targets)

obj.select_set(True)
else:
self.modifier_names = tuple(i.name for i in obj.modifiers)
self.flags = tuple(False for i in range(32))
return {'FINISHED'}

def invoke(self, context, event):
wm = context.window_manager
obj = context.object
self.modifier_names = tuple(i.name for i in obj.modifiers)
self.flags = tuple(False for i in range(32))
return wm.invoke_props_dialog(self)

def draw(self, context):
Expand All @@ -275,7 +286,8 @@ def draw(self, context):
layout = self.layout
col = layout.column()

for i in range(len(self.modifier_names)):
usable_slots = min(len(self.modifier_names), 32)
for i in range(usable_slots):
col.prop(self, "flags", text=self.modifier_names[i], index=i)


Expand Down