0

I want to link two mesh objects and keep the UV mapping each one has and I've found solution here, but for me script doesn't work. I'm getting error:

AttributeError: bpy_prop_collection: attribute "link" not found

in 30 line. I've found information about replacing collection system in Blender 2.8 but I don't know how to use that information. I'm using Blender 4.0.2. How can I fix this script?

Full script:

# make sure to be in Object mode
# make sure to have two objects selected
import bpy
import bmesh
from mathutils import Matrix
from contextlib import ExitStack

def work(): C = bpy.context if C.mode != 'OBJECT': return if len(C.selected_objects) < 1: print("Must have at least one object selected") return # read into bmesh safely names = [] with ExitStack() as stack: bm = bmesh.new() stack.callback(bm.free) for o in C.selected_objects: if o.type != 'MESH': continue m = o.matrix_world bm.transform(m.inverted()) bm.from_mesh(o.data) bm.transform(m) names.append(o.name) # write to actual mesh mesh = bpy.data.meshes.new('Result') object = bpy.data.objects.new('Merge(%s)' % ', '.join(names), mesh) bm.to_mesh(mesh) C.scene.objects.link(object) C.scene.update()

work()

Сергей
  • 922
  • 6
  • 14

1 Answers1

2

These points have been changed with Blender 2.8

line 32: see here

old: context.scene.objects.link(object)
new: context.collection.objects.link(object)

line 33: see here

old: context.scene.update()
new: context.view_layer.update()
relaxed
  • 2,267
  • 6
  • 15
  • Yes, I've tried this one, but are you sure it's right option? In my case merge's result doesn't have any materials. Maybe, there is error in original script - in that case your answer is right. – Сергей Feb 03 '24 at 17:33