lucanapo
lucanapo

Reputation: 59

bpy.ops.sequencer.view_all() poll fails

I ask for help because I literally have no idea what I have to do for this. I'm bangin my head for 2 days and I have to admit that I just dont get it...

I need a script to set the view in the sequencer to bpy.ops.sequencer.view_all() (or similarly: bpy.ops.sequencer.view_selected())

To do that I need to override the context and tell the script it has to run that command in the sequencer area, if not it will give a:

Python: Traceback (most recent call last):
  File "\Text", line 4, in <module>
  File "F:\MEDIA\GAMES\Steam\steamapps\common\Blender\3.4\scripts\modules\bpy\ops.py", line 113, in __call__
    ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.sequencer.view_all.poll() failed, context is incorrect

..and of course just setting:

bpy.context.area.ui_type = 'SEQUENCE_EDITOR'

..does nothing But again I have absolutely no idea what to do so, any help would be highly apreciated..

Upvotes: 2

Views: 482

Answers (1)

Joe
Joe

Reputation: 471

Here is the correct context override:

import bpy

# go through all areas until sequence editor is found
for area in bpy.context.screen.areas:
    if area.type == "SEQUENCE_EDITOR":
        override = bpy.context.copy()
        # change context to the sequencer
        override["area"] = area
        override["region"] = area.regions[-1]
        # run the command with the correct context
        with bpy.context.temp_override(**override):
            bpy.ops.sequencer.view_all()
        break

Upvotes: 2

Related Questions