1

Modifiers cannot be applied to multi-user data - how can I solve for complex deeply nested meshes via Python

I have looked at https://blender.stackexchange.com/a/253286/151885 is there a way to set this option in the API?

This seems to be a slightly different context than my issue, where I'm importing many gltf files via a headless script, whereas they're working in the editor.

t3hbr0k3n
  • 33
  • 7

1 Answers1

1

Apply modifier to multi-user

import bpy

def apply_md_by_name(name): try: bpy.ops.object.modifier_apply(modifier=name) return True except: # wrong name, modifier disabled, no data to apply, ... bpy.ops.object.modifier_remove(modifier=name) return False

def apply_md(obj, md_name): try: # set active object bpy.context.view_layer.objects.active = obj

    # add a mesh to blend data
    temp = bpy.data.meshes.new("temp")

    # get users
    me = obj.data
    users = [o for o in bpy.data.objects if o.data == me and o != obj]

    for u in users:
        u.data = temp

    apply_md_by_name(md_name)

    for u in users:
        u.data = me

    bpy.data.meshes.remove(temp)
    del users
except:
    print("    Fail")
    # not in object mode, wrong name, ...

apply_md(bpy.context.object, "Bevel")

X Y
  • 5,234
  • 1
  • 6
  • 20