# Duplicating element with python, rigid body lost

So at first I was using this while having selected what I wanted to duplicate before :

bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, PH+PH), "constraint_axis":(False, False, True), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})


But for no reason that I could find the translation would not be made anymore, it would still duplicate but it would then left it at the same position.

Then I read : Duplicating a mesh object

and when using :

new_obj = obj.copy()
new_obj.data = obj.data.copy()
new_obj.animation_data_clear()
new_obj.location = new_obj.location + mathutils.Vector((0, 0, PH+PH))


the objects are duplicated and translated as I want but the rigidbody from the original object is lost.

I tried adding a new rigidbody on the new object but this is slow as hell (by adding this)

obj.select = True
bpy.context.object.rigid_body.collision_shape = 'BOX'
bpy.context.object.rigid_body.use_margin = True
bpy.context.object.rigid_body.collision_margin = 0.01


would anyone know why the duplicate_move stopped working? is there a fastest way to duplicate the rigidbody?

Thanks.

The code you got from this answer does actually copy the rigid body settings, what it doesn't do is add the new object to the rigid body group. Without being part of the rigid body group the objects don't act as rigid body objects, even with the settings.

import bpy

scn = bpy.context.scene
src_obj = bpy.context.active_object
rbgroup = scn.rigidbody_world.group

for i in range (1,6):
new_obj = src_obj.copy()
new_obj.data = src_obj.data.copy()
new_obj.animation_data_clear()