I'm trying to lie a object on a surface for 3D printing it afterwards.
In other words, I want to find a way to automatically position a complex object the best way on a printing table. Here is a sample picture of an object:
Therefore my idea was to use the gravity aimation of blender:
ctx = bpy.context
obj = ctx.scene.objects.active
ob.select = True
bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')
obj.location = (0,0,0)
bpy.ops.object.transform_apply(location=True, rotation=True, scale=False)
bpy.ops.rigidbody.object_add()
obj.rigid_body.type = 'ACTIVE'
mod_col = obj.modifiers.new('col', 'COLLISION')
bpy.ops.object.modifier_apply(apply_as='DATA', modifier='col')
plane = bpy.ops.mesh.primitive_plane_add(radius=(obj.dimensions[0]+obj.dimensions[1]), location=(0,0,(obj.dimensions[2]/(-2))-1))
plane = bpy.context.active_object
plane.name = 'Plane'
bpy.ops.rigidbody.object_add()
plane.rigid_body.type = 'PASSIVE'
mod_col = plane.modifiers.new('col', 'COLLISION')
bpy.ops.object.modifier_apply(apply_as='DATA', modifier='col')
ctx.scene.frame_start = 0
ctx.scene.frame_end = 250
bpy.data.scenes['Scene'].gravity[2] = -50
bpy.ops.screen.animation_play()
if scene.frame_current == 249:
bpy.ops.screen.animation_cancel(restore_frame=False)
obj = ctx.scene.objects.active
bpy.ops.object.transform_apply(location=True, rotation=True, scale=False)
bpy.ops.object.visual_transform_apply()
bpy.ops.object.anim_transforms_to_deltas()
plane.select = True
bpy.ops.object.delete()
Till now the animation won't stop at the last frame.
Is there a better way to lie the object flat and if not, how can I stop the animation at the last frame?