1
$\begingroup$

How can I copy objects without linking data via python?(That is deep copy the object data.)

I'm using this to copy objects, but the new object's data linked to origin.

obj=bpy.context.object
obj_data = obj.data.copy()
obj_1 = obj.copy()
obj_1.data = obj_data
bpy.context.collection.objects.link(obj_1)

enter image description here

I don't want this result.

I want this:(CTRL+C CTRL+V)

enter image description here

How can I make it via python?

$\endgroup$

1 Answer 1

1
$\begingroup$

I just hit on the idea myself!

new_obj=[]
for obj in context.selected_objects:
    # duplicate the object
    obj_data = obj.data.copy()
    obj_1 = obj.copy()
    obj_1.data = obj_data
    bpy.context.collection.objects.link(obj_1)
    new_obj.append(obj_1)
bpy.ops.object.select_all(action='DESELECT')
for obj in new_obj:
    obj.select_set(state=True)
    context.view_layer.objects.active = obj
    bpy.ops.object.make_single_user(object=True, obdata=True, material=True, animation=False,obdata_animation=False)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .