-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplyAllModifiers.py
63 lines (46 loc) · 1.67 KB
/
ApplyAllModifiers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
bl_info = {
"name": "Apply all modifiers of selected objects",
"category": "Object",
"author": "Deadolus",
"version": (1,0,0),
"blender": (2,80,0),
"warning": "",
"location": "Object > Apply > Apply all modifiers of selected objects",
}
import bpy
def main(context):
#for ob in context.scene.objects:
#print(ob)
#bpy.ops.object.select_all(action='DESELECT')
#bpy.ops.object.select_all(action='SELECT')
act = context.active_object
old_active = act
sel = context.selected_objects
for obj in sel:
bpy.context.view_layer.objects.active = obj
for mod in obj.modifiers:
bpy.ops.object.modifier_apply(modifier=mod.name)
context.view_layer.objects.active = old_active
class ApplyAllModifiersOperator(bpy.types.Operator):
"""Apply all modifiers of selected objects"""
bl_idname = "object.apply_all_modifiers"
bl_label = "Apply all modifiers of selected objects"
bl_options = {'REGISTER', 'UNDO'} # Enable undo for the operator.
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
main(context)
return {'FINISHED'}
def menu_func(self, context):
self.layout.operator("object.apply_all_modifiers")
# bl_idname should be in form of "something.something"
# or YourClass.bl_idname
def register():
bpy.utils.register_class(ApplyAllModifiersOperator)
bpy.types.VIEW3D_MT_object_apply.append(menu_func)
def unregister():
bpy.utils.unregister_class(ApplyAllModifiersOperator)
bpy.types.VIEW3D_MT_object_apply.remove(menu_func)
if __name__ == "__main__":
register()