Skip to content

Instantly share code, notes, and snippets.

@tobyapi
Created January 22, 2022 04:20
Show Gist options
  • Select an option

  • Save tobyapi/1810d4ab1d09aa5c5006029e341c43f8 to your computer and use it in GitHub Desktop.

Select an option

Save tobyapi/1810d4ab1d09aa5c5006029e341c43f8 to your computer and use it in GitHub Desktop.
Blender のアーマチュア以外の全てのモディファイアを適用するやつ
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