I am trying to run a cloth simulator (using the Blender Render) and save the garments meshes at a given frame via python scripting. I have the code that would do that in the graphical interface (through the python console), but in the script the simulation does not start and it always saves the original mesh.
More specifically, after I load the meshes and set up the scene in the script, I am trying to save the shirt mesh:
shirt = D.objects['shirt'] bpy.context.scene.frame_set(55) for ob in D.objects: ob.select = False shirt.select = True bpy.context.scene.objects.active = shirt bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Cloth") # Saves the mesh as an object bpy.ops.export_scene.obj(filepath='shirt.obj', use_selection=True)
I have tried to start the simulation with
bpy.ops.screen.animation_play() (the bit of code that pops up when I press the play button in the graphical interface), but it does nothing.
How do I start the simulation in the script so that I can save the updated mesh?