0
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ How did you set up the simulation prior to advancing the frames? $\endgroup$ – Jack Lynch Mar 30 '19 at 12:49
1
$\begingroup$

It turns out that I had to advance the iteration frame by frame, like:

for frame_no in range(55):
    print ('Running frame {}..'.format(frame_no))
    bpy.context.scene.frame_set(frame_no + bpy.data.scenes["Scene"].frame_start)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.