1
$\begingroup$

I'm trying to create a Python program by which a user could look at randomly generated poses of 3D model and choose if it to be saved in Pose Library until certain number of poses will be added. This is mentioned part of my code at the moment:

scene = bpy.context.scene
fp = os.path.join(bpy.path.abspath("//"), 'Poses') 
scene.render.image_settings.file_format = 'PNG'

num_poses = 0

while num_poses < 10:
    # Randomly generate pose
    # Missing as not important

    # Saving image of current pose to file so user can see it
    scene.render.filepath = os.path.join(fp, 'New Pose')
    bpy.ops.render.render(write_still=True) 

    # User chooses if it wants to save pose to Pose Library
    answer = input('Do you want to save this pose(y,n)? ')

    if answer == 'y':
        bpy.ops.poselib.pose_add(name=str(num_poses))
        num_poses += 1 

The problem is that only the last pose is saved. If I understand correctly it should have something to do with frame number but when I tried to use

bpy.ops.poselib.pose_add(frame = 1+num_poses, name=str(num_poses))

only part of armature was changing when saved pose was selected.

I would be very thankful if somebody could help me or at least point me in the right direction.

$\endgroup$
0
$\begingroup$

I find a solution. If somebody else would want to do that, here's the code:

bpy.ops.pose.select_all(action="TOGGLE")
bpy.ops.poselib.pose_add(frame=1+num_poses,name=str(num_poses))
bpy.ops.pose.select_all(action="DESELECT")

Before adding new poses, Blender requires that you select and deselect pose. Otherwise not whole armature is saved.

| improve this answer | |
$\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.