Duplicate Meshes using Python

I’m trying to duplicate a selection of meshes in Blender using Python. The code works but the problem is that the meshes lose their linked instances (they all become single users). I want them to remain instances of each other after .copy(). How do I do this?

for obj in bpy.context.selected_objects:
bpy.ops.object.select_all(action=‘DESELECT’)
# duplicate meshes
new_obj = obj.copy()
new_obj.data = obj.data.copy() # Omit if you want a linked object.
new_coll.objects.link(new_obj)

In order to keep linked data, use
new_obj.data = obj.data

1 Like

Thanks! Works

Hmm, actually I would like it not to be linked to the original meshes. For e.g I have a box and 5 linked duplicates. I want to duplicate this group of boxes (shift + D) to another new dynasty that still are linked to each other but are unique from the initial group. So each group should have 2 parent boxes and each with 5 linked boxes.

so first one is a copy
me = old.data.copy()

then link new ones to that copy
new_obj.data = me

for obj in bpy.context.selected_objects:
bpy.ops.object.select_all(action=‘DESELECT’)
# duplicate meshes
new_obj = obj.copy()
me = old.data.copy()
new_obj.data = me
new_coll.objects.link(new_obj)

Like this? It doesn’t recognize “old” keyword

I have a scene with many different objects with linked duplicates and want to duplicate them into separate objects but save the linked duplicate relationship within the new group.

Create “number_of_copy” of every selected object, where new objects are linked together.
Copy are all at same location, you have to move them according your needs.

sel = bpy.context.selected_objects
number_of copy = 3
bpy.ops.object.select_all(action=‘DESELECT’)
for obj in sel:
    me = obj.data.copy()
    for i in range(number_of_copy):
        new_obj = obj.copy()
        new_obj.data = me

Thanks but the function is not what I need. It’s just duplicating everything as instances
image

This is what I need