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