Blender Script for animated remeshing just works “sometimes”

This Script I wrote for remeshing purposes does not work properly. Sometimes it works. Sometimes it produces many (as many as frames) duplicates of the active Object.

import bpy

frame_end = bpy.context.scene.frame_end
sel_Objects = bpy.context.selected_objects

cuts = []

if(len(sel_Objects) == 2):

for i in range(frame_end):

bpy.context.scene.frame_set(i)

bpy.ops.object.select_all(action='DESELECT')
sel_Objects[0].select = True
sel_Objects[1].select = True
bpy.context.scene.objects.active = sel_Objects[0]

bpy.ops.object.duplicate()
bpy.ops.object.join()

to_delete = bpy.context.scene.objects.active

bpy.ops.object.editmode_toggle()
bpy.ops.mesh.intersect(mode='SELECT', use_separate=True)
bpy.ops.mesh.separate()
bpy.ops.object.editmode_toggle()

bpy.data.objects.remove(to_delete)

cuts.extend(bpy.context.selected_objects)

bpy.ops.object.select_all(action='DESELECT')
for cut in cuts:
cut.select = True

bpy.context.scene.objects.active = cuts[0]
bpy.ops.object.join()


The script should performe the following actions:

• Before you have two animated Objects intersecting each other while the animation.

• After running the script you should still have the two animated Objects but also the intersections of the two objects merged into one mesh.

But this is how it looks like:

The problem @this point is that the script doesn't clear several duplicates of , in this case the torus.

• You are using a lot of operators - could be an issue. What the script should do exactly? Error messages? Could you please provide a sample scene? – p2or Apr 21 '15 at 8:08
• Agreed, please describe what the script is supposed to be doing, and add a small image of a representative scene so we can reproduce the scenario and adjust the code where possible. – zeffii Apr 21 '15 at 10:41
• try with these lines cut = bpy.context.selected_objects[0] cut.animation_data_clear() cuts.extend(bpy.context.selected_objects) – Chebhou Apr 21 '15 at 13:15
• @schwenk still having a problem ? – Chebhou Apr 22 '15 at 18:49