How to use bpy.data.objects.copy() to duplicate object? [not bpy.ops.object.duplicate]

Hi guys,

I have executed the code of

bpy.data.objects['Cube'].copy()

The console returns,

bpy.data.objects['Cube.001']

This means I have successfully copied the object. However, when I check back to the scene, I cannot find the object, nor can I find it in the object drop down list.

I would love to know if it is a problem of not making it into the scene? And how to do it?

Is there a way to duplicate the object and make it visible in the active scene without using the method of:

bpy.ops.object.duplicate

The above method needs an active_object while I need to target an object by name.

Hi,
objects are not automatically included in the scene, you need to add :
bpy.context.scene.collection.objects.link(my_new_object)

1 Like

Amazing,

I used the code:

bpy.context.scene.objects.link(bpy.data.objects['Cube.001'])

Thanks a lot!