Fix T103455: Modifier tools add-on don't support GPencil modifiers
Modifier stack for GPencil object is handled separately than the geometry objects (mesh/Curve). This patch provides support for GPencil modifier. `modifier_type` function is added to assign correct modifier list according to the object type. Reviewed by: antoniov Differential Revision: https://developer.blender.org/D16865
This commit is contained in:
parent
e3a224f473
commit
f131c922f9
Notes:
blender-bot
2023-02-14 18:10:37 +01:00
Referenced by issue blender/blender#88449: Blender LTS: Maintenance Task 2.93 Referenced by issue blender/blender#100749: Blender LTS: Maintenance Task 3.3 Referenced by issue blender/blender#88449, Blender LTS: Maintenance Task 2.93 Referenced by issue blender/blender#100749, Blender LTS: Maintenance Task 3.3 Referenced by issue #103455, Modifier tools don't support greasepencil modifiers
|
@ -37,7 +37,9 @@ class ApplyAllModifiers(Operator):
|
|||
contx = bpy.context.copy()
|
||||
contx['object'] = obj
|
||||
|
||||
for mod in obj.modifiers[:]:
|
||||
modifiers = modifier_type(obj)
|
||||
|
||||
for mod in modifiers[:]:
|
||||
contx['modifier'] = mod
|
||||
is_mod = True
|
||||
try:
|
||||
|
@ -45,6 +47,10 @@ class ApplyAllModifiers(Operator):
|
|||
contx,
|
||||
modifier=contx['modifier'].name
|
||||
)
|
||||
|
||||
bpy.ops.object.gpencil_modifier_apply(
|
||||
modifier=contx['modifier'].name
|
||||
)
|
||||
except:
|
||||
obj_name = getattr(obj, "name", "NO NAME")
|
||||
collect_names.append(obj_name)
|
||||
|
@ -90,10 +96,11 @@ class DeleteAllModifiers(Operator):
|
|||
|
||||
for obj in context.selected_objects:
|
||||
is_select = True
|
||||
modifiers = obj.modifiers[:]
|
||||
for modi in modifiers:
|
||||
modifiers = modifier_type(obj)
|
||||
|
||||
for modi in modifiers[:]:
|
||||
is_mod = True
|
||||
obj.modifiers.remove(modi)
|
||||
modifiers.remove(modi)
|
||||
|
||||
if is_select:
|
||||
if is_mod:
|
||||
|
@ -127,12 +134,16 @@ class ToggleApplyModifiersView(Operator):
|
|||
skipped = set() # collect names
|
||||
count_modifiers = 0 # check for message_a (all skipped)
|
||||
|
||||
modifiers = modifier_type(context.active_object)
|
||||
|
||||
# check if the active object has only one non exposed modifier as the logic will fail
|
||||
if len(context.active_object.modifiers) == 1 and \
|
||||
context.active_object.modifiers[0].type in skip_type:
|
||||
if len(modifiers) == 1 and \
|
||||
modifiers[0].type in skip_type:
|
||||
|
||||
for obj in context.selected_objects:
|
||||
for mod in obj.modifiers:
|
||||
mod_sel = modifier_type(obj)
|
||||
|
||||
for mod in mod_sel:
|
||||
if mod.type in skip_type:
|
||||
skipped.add(mod.name)
|
||||
continue
|
||||
|
@ -141,7 +152,7 @@ class ToggleApplyModifiersView(Operator):
|
|||
is_apply = False
|
||||
break
|
||||
else:
|
||||
for mod in context.active_object.modifiers:
|
||||
for mod in modifiers:
|
||||
if mod.type in skip_type:
|
||||
skipped.add(mod.name)
|
||||
continue
|
||||
|
@ -150,9 +161,9 @@ class ToggleApplyModifiersView(Operator):
|
|||
is_apply = False
|
||||
break
|
||||
|
||||
count_modifiers = len(context.active_object.modifiers)
|
||||
count_modifiers = len(modifiers)
|
||||
# active object - no selection
|
||||
for mod in context.active_object.modifiers:
|
||||
for mod in modifiers:
|
||||
if mod.type in skip_type:
|
||||
count_modifiers -= 1
|
||||
skipped.add(mod.name)
|
||||
|
@ -161,9 +172,12 @@ class ToggleApplyModifiersView(Operator):
|
|||
mod.show_viewport = is_apply
|
||||
|
||||
for obj in context.selected_objects:
|
||||
count_modifiers += len(obj.modifiers)
|
||||
|
||||
for mod in obj.modifiers:
|
||||
modifiers = modifier_type(obj)
|
||||
|
||||
count_modifiers += len(modifiers)
|
||||
|
||||
for mod in modifiers:
|
||||
if mod.type in skip_type:
|
||||
skipped.add(mod.name)
|
||||
count_modifiers -= 1
|
||||
|
@ -194,9 +208,11 @@ class ToggleAllShowExpanded(Operator):
|
|||
|
||||
def execute(self, context):
|
||||
obj = context.active_object
|
||||
if (len(obj.modifiers)):
|
||||
modifiers = modifier_type(obj)
|
||||
|
||||
if (len(modifiers)):
|
||||
vs = 0
|
||||
for mod in obj.modifiers:
|
||||
for mod in modifiers:
|
||||
if (mod.show_expanded):
|
||||
vs += 1
|
||||
else:
|
||||
|
@ -204,7 +220,7 @@ class ToggleAllShowExpanded(Operator):
|
|||
is_close = False
|
||||
if (0 < vs):
|
||||
is_close = True
|
||||
for mod in obj.modifiers:
|
||||
for mod in modifiers:
|
||||
mod.show_expanded = not is_close
|
||||
else:
|
||||
self.report({'WARNING'}, "Not a single modifier to Expand/Collapse")
|
||||
|
@ -218,7 +234,7 @@ class ToggleAllShowExpanded(Operator):
|
|||
# Menus #
|
||||
def menu(self, context):
|
||||
if (context.active_object):
|
||||
if (len(context.active_object.modifiers)):
|
||||
if (len(context.active_object.modifiers) or len(context.active_object.grease_pencil_modifiers)):
|
||||
col = self.layout.column(align=True)
|
||||
|
||||
row = col.row(align=True)
|
||||
|
@ -238,13 +254,18 @@ def menu(self, context):
|
|||
|
||||
def menu_func(self, context):
|
||||
if (context.active_object):
|
||||
if (len(context.active_object.modifiers)):
|
||||
if (len(context.active_object.modifiers) or len(context.active_object.grease_pencil_modifiers)):
|
||||
layout = self.layout
|
||||
layout.separator()
|
||||
layout.operator(ApplyAllModifiers.bl_idname,
|
||||
icon='IMPORT',
|
||||
text="Apply All Modifiers")
|
||||
|
||||
def modifier_type(object):
|
||||
if object.type == 'GPENCIL':
|
||||
return object.grease_pencil_modifiers
|
||||
return object.modifiers
|
||||
|
||||
# Register
|
||||
classes = [
|
||||
ApplyAllModifiers,
|
||||
|
@ -261,6 +282,8 @@ def register():
|
|||
# Add "Specials" menu to the "Modifiers" menu
|
||||
bpy.types.DATA_PT_modifiers.prepend(menu)
|
||||
|
||||
bpy.types.DATA_PT_gpencil_modifiers.prepend(menu)
|
||||
|
||||
# Add apply operator to the Apply 3D View Menu
|
||||
bpy.types.VIEW3D_MT_object_apply.append(menu_func)
|
||||
|
||||
|
@ -269,6 +292,8 @@ def unregister():
|
|||
# Remove "Specials" menu from the "Modifiers" menu.
|
||||
bpy.types.DATA_PT_modifiers.remove(menu)
|
||||
|
||||
bpy.types.DATA_PT_gpencil_modifiers.remove(menu)
|
||||
|
||||
# Remove apply operator to the Apply 3D View Menu
|
||||
bpy.types.VIEW3D_MT_object_apply.remove(menu_func)
|
||||
|
||||
|
|
Loading…
Reference in New Issue