Created
January 22, 2022 04:20
-
-
Save tobyapi/1810d4ab1d09aa5c5006029e341c43f8 to your computer and use it in GitHub Desktop.
Blender のアーマチュア以外の全てのモディファイアを適用するやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import bpy | |
| def apply_modifiers(obj): | |
| ctx = bpy.context.copy() | |
| modifiers = [m for _, m in enumerate(obj.modifiers) if m.type != 'ARMATURE'] | |
| for m in modifiers: | |
| try: | |
| ctx['modifier'] = m | |
| bpy.ops.object.modifier_apply(ctx, modifier=m.name) | |
| except RuntimeError: | |
| print(f'Error applying {m.name} to {obj.name}.') | |
| obj.modifiers.remove(m) | |
| for m in obj.modifiers: | |
| if m.type != 'ARMATURE': | |
| obj.modifiers.remove(m) | |
| for o in bpy.context.view_layer.objects: | |
| o.select_set(o.type == 'MESH') | |
| bpy.context.view_layer.objects.active = o | |
| apply_modifiers(o) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment