0
$\begingroup$

I would like to replace objects at the end of a rigid body simulation by a another object. But the final scene contains the old ones, even when I call obj.hide=True on the original object. The new objects ARE in the scene, but on the pose where the simulation started not at the final frame.

What the replace function does: Traversing a list of objects to be replaced. Copy a "template" object and put it to the location of the original object.

def duplicate_and_replace(lst_obj,obj_name):

    scn = bpy.context.scene
    obj_name_rgb = obj_name.replace("tex", "rgb")
    obj_rgb = bpy.data.objects[obj_name_rgb]

    for obj in lst_obj:
        new_obj = obj_rgb.copy()
        new_obj.data = obj_rgb.data.copy()
        new_obj.animation_data_clear()
        scn.objects.link(new_obj)
        new_obj.location = obj.location
        new_obj.rotation_euler = obj.rotation_euler
        obj.hide=True
$\endgroup$
0
$\begingroup$

The following code works for me now:

new_obj.location = obj.matrix_world.translation
new_obj.rotation_euler = obj.matrix_world.to_euler()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.