I have a project I am working on where I have objects positions randomly in the space and let them fall using rigid body simulation using python scripts and blender as (GUI-less) background. I am able to get the initial position and final position (after 500 frames). Now I would like to also generate video of the free fall of the objects from frame 1-500 into a video file as scene by the camera. I am able to generate images using node-editor at the end of the simulation. I am looking for a flag that is like below pseudo code.
start recording
start the free fall
end after 500 frames
stop recording
Any pointers would be of great help! Thanks in advance.
Edit1: To clarify more on what I want to do! Thing to note here is that, I have single python script and I am generating 10 different scenes one after the other, where each scene has objects positions randomly. Currently I am using bake-all method to get the final state of each scene and render the scene out to see whats the final stage. Now instead of getting the final frame for all these scenes, I want to start the animation before baking each scene and render it out to a video. I want to do this for each scene one by one in the loop.
Edit2: I guess I am in the process of figuring it out. I found out that
bpy.ops.rigidbody.objects_add(type='ACTIVE')
bpy.ops.ptcache.bake_all(bake=True)
Does do the physics simulation before hand store it in a file. Now all I have to do is to do the below to get the animaton? I will post the results when I find it.
bpy.context.scene.camera = camera
bpy.ops.render.render(write_still=True)