I am trying to apply a pose asset to an object and keyframe it.
To do this I followed the approach from this question.
I adapted the code for the question's answer to use the newer temp_override
as suggested.
def apply_pose(frame, pose):
win = bpy.context.window
scr = win.screen
area = scr.areas[0]
area.type = "FILE_BROWSER"
area.ui_type = "ASSETS"
region = "EMPTY"
for i in area.regions:
if i.type == "TOOLS":
region = i
print(region)
with bpy.context.temp_override(window=win, screen=scr, area=area, region=region, active_object=bpy.context.selected_objects[0]):
print(pose)
bpy.context.scene.frame_set(frame)
bpy.ops.object.mode_set(mode='POSE')
# Alternative for setting active object doesn't work either
# bpy.context.view_layer.objects.active = bpy.context.selected_objects[0]
bpy.context.object.animation_data.action = bpy.data.actions[pose]
bpy.ops.poselib.apply_pose_asset(blend_factor=1, flipped=False)
The following error occurs: RuntimeError: Operator bpy.ops.poselib.apply_pose_asset.poll() failed, context is incorrect
I would assume that the current area for the execution of this operator is the asset browser (ASSETS
). However, when I try to set the area to ASSETS
the following error occurs:
enum "ASSETS" not found in ('EMPTY', 'VIEW_3D', 'IMAGE_EDITOR', 'NODE_EDITOR', 'SEQUENCE_EDITOR', 'CLIP_EDITOR', 'DOPESHEET_EDITOR', 'GRAPH_EDITOR', 'NLA_EDITOR', 'TEXT_EDITOR', 'CONSOLE', 'INFO', 'TOPBAR', 'STATUSBAR', 'OUTLINER', 'PROPERTIES', 'FILE_BROWSER', 'SPREADSHEET', 'PREFERENCES')
EDIT:
This was the selected object when the operation was performed.
type
isFILE_BROWSER
but you also have to set theui_type
to "ASSETS". docs.blender.org/api/current/… $\endgroup$active_object
$\endgroup$active_object
also does not work. $\endgroup$