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()