EDIT: pointed out in a comment: my code needed some error handling and I didn't demonstrate how to use an override with arguments.
Here is an example of how to use an override to allow you to invoke apply_pose_asset
:
win = bpy.context.window
scr = win.screen
assets = [area for area in scr.areas if area.type == 'FILE_BROWSER']
if len(assets):
region = [region for region in assets[0].regions if region.type == 'TOOLS']
if len(region):
override = {
'window': win,
'screen': scr,
'area' : assets[0],
'region': region[0],
'scene' : bpy.context.scene,
}
bpy.ops.poselib.apply_pose_asset(override, blend_factor=1, flipped=False)
else:
print("Current Pose Library does not have a tools menu open.")
else:
print("There is no Pose LIbrary open.")
The override is inserted into the function call as the first argument, all other arguments remaining the same.
The override argument takes the form of a Python dictionary. Each entry represents one piece of context to override. The above example shows the complete override for the command. Note that the area type is FILE_BROWSER
. That is the area type of the editor window that the command expects to run in.
Note: The command itself uses the first valid entry in the catalog if none are selected, or the active entry if one is selected.
bpy.ops.poselib.apply_pose(pose_index=- 1)
is currently an operator designed for the deprecated (but still functional) separate version of the Pose Library system, soon to be removed post Blender 3.1. It exists in the Properties sidebar as a tab in Armature's settings. It requires its own pose entries and 'PROPERTIES'
area type context to be executed. Like so:
import bpy
bpy.ops.poselib.apply_pose({'area':'PROPERTIES'}, pose_index=0)
3.2 Update
Context overrides are deprecated in Blender 3.2 and are scheduled to be removed in Blender 3.3 The replacement is temp_override
. The manual has examples of how to use the new function.
bpy.ops.poselib.apply_pose_asset(blend_factor=1, flipped=False)
so it's definitely using these operators somehow $\endgroup$