Apply pose, rotate and render

Hello,

I have a rigged model and small library of poses. I’d like to automatically render it into sprites by:

  1. Rotate to specific angle
  2. Apply specific poses
  3. Render and save to file
  4. Repeat

Seems quite straight forward, right?

Well I have some issues making it work. This is what I got so far:

import bpy
import math

#this is my character
BasePerson = bpy.context.scene.objects["BasePerson"]

def RenderIn8Directions():
   #here I rotate to specific angle
    BasePerson.rotation_euler[2] = math.radians(0)
   #I provide path
    bpy.context.scene.render.filepath = "//test1.png"
   #And I save the file
    bpy.ops.render.render(write_still = 1)

    BasePerson.rotation_euler[2] = math.radians(315)
    bpy.context.scene.render.filepath = "//test2.png"
    bpy.ops.render.render(write_still = 1)

    BasePerson.rotation_euler[2] = math.radians(270)
    bpy.context.scene.render.filepath = "//test3.png"
    bpy.ops.render.render(write_still = 1)

    BasePerson.rotation_euler[2] = math.radians(225)
    bpy.context.scene.render.filepath = "//test4.png"
    bpy.ops.render.render(write_still = 1)

    BasePerson.rotation_euler[2] = math.radians(180)
    bpy.context.scene.render.filepath = "//test5.png"
    bpy.ops.render.render(write_still = 1)

    BasePerson.rotation_euler[2] = math.radians(135)
    bpy.context.scene.render.filepath = "//test6.png"
    bpy.ops.render.render(write_still = 1)

    BasePerson.rotation_euler[2] = math.radians(90)
    bpy.context.scene.render.filepath = "//test7.png"
    bpy.ops.render.render(write_still = 1)

    BasePerson.rotation_euler[2] = math.radians(45)
    bpy.context.scene.render.filepath = "//test8.png"
    bpy.ops.render.render(write_still = 1)
 
    BasePerson.rotation_euler[2] = math.radians(0)
        
#here I'm changing mode to "Object" to properly select my object
bpy.ops.object.mode_set(mode = 'OBJECT')

#here I'm selecting my character
bpy.data.objects["BasePerson"].select_set(True)

#here I'm trying to apply pose. None of those work though.
bpy.ops.poselib.apply_pose(pose_index=- 1)
bpy.data.actions["PoseLib"].pose_markers.active_index = 5

RenderIn8Directions()

Rotating and saving works ok, but despite hours of googling I have no working solution on how to apply poses. I mean it can’t be that complicated, right? It’s just one mouse click from UI.

My Pose Library is called “PoseLib” and my poses are named “Walk_1”, “Walk_2”, “LookRight”, “LookLeft”.

Please kind people, do you know how to make this work?

Best regards