Howdy
Im very new to Blender and and python and have written a simple script in python
to generate random poses of my rigged mesh.
The script works fine when n=1 and i push the Run Script button multiple times -> I see multiple different poses in the 3D viewport.
I now want to set n = 100 and see the poses displayed one after the other in the vieport. Unfortunately this doesnt happen. Instead I see the first pose, a long delay and then the last pose. There is no update of the viewport.
How can I force the viewport to update at the end of my loop? bpy.data.scenes[0].update() doesnt seem to do anything.
import bpy
import random
import time
hand_pose = bpy.data.objects["Armature"].pose;
for bone in hand_pose.bones:
bone.rotation_mode = "XYZ";
bone.rotation_euler = (0,0,0);
# bone_name - which bone
# phi - left right angle
# theta - forward backward angle
def set_rot( pose, bone_name, phi_lims, theta_lims ):
phi = phi_lims[0] + random.random() * (phi_lims[1] - phi_lims[0]);
theta = theta_lims[0] + random.random() * (theta_lims[1] - theta_lims[0]);
pose.bones[bone_name].rotation_euler = ( -phi/57.3, 0 , -theta/57.3 );
return
n = 100
i = 0
while i < n:
i = i + 1;
set_rot(hand_pose, 'wrist', ( -10 , 10 ), ( -30 , 30 ) );
set_rot(hand_pose, 'pinkybase', ( -3 , 3 ), ( -2 , 2 ) );
set_rot(hand_pose, 'pinkylower', ( -5 , 5 ), ( -3 , 90 ) );
set_rot(hand_pose, 'pinkymiddle', ( 0 , 0 ), ( 0 , 90 ) );
set_rot(hand_pose, 'pinkytop', ( 0 , 0 ), ( 0 , 90 ) );
bpy.data.scenes[0].update() # <-- PROBLEM?
# bpy.ops.render.render( write_still=True )