0
$\begingroup$

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.

Object Outline

$\endgroup$
4
  • $\begingroup$ The type is FILE_BROWSER but you also have to set the ui_type to "ASSETS". docs.blender.org/api/current/… $\endgroup$
    – Gorgious
    Commented Sep 19, 2022 at 11:15
  • $\begingroup$ @Gorgious Thank you, I updated the code (also in the question) but the context is still invalid. $\endgroup$
    – Ph.lpp
    Commented Sep 19, 2022 at 19:18
  • $\begingroup$ Didn't test it but I think you have to also override active_object $\endgroup$
    – Gorgious
    Commented Sep 20, 2022 at 6:49
  • $\begingroup$ Sorry, but setting the active_object also does not work. $\endgroup$
    – Ph.lpp
    Commented Sep 20, 2022 at 8:06

0

You must log in to answer this question.

Browse other questions tagged .