1
$\begingroup$

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()
scn.objects.link(new_obj)
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.ops.rigidbody.objects_add()
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.

$\endgroup$

1 Answer 1

2
$\begingroup$

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()
    scn.objects.link(new_obj)
    rbgroup.objects.link(new_obj)
    new_obj.location.z = i * 3
$\endgroup$
1
  • $\begingroup$ working perfectly :D $\endgroup$ May 9, 2018 at 10:25

You must log in to answer this question.

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