python bpy.ops.sequencer.view_all()轮询失败

wfveoks0  于 2023-02-07  发布在  Python
关注(0)|答案(1)|浏览(124)

我寻求帮助是因为我真的不知道我该做些什么。我的头撞了两天,我不得不承认我只是不明白...
我需要一个脚本来将Sequencer中的视图设置为bpy.ops.sequencer.view_all()(或者类似地:bpy.操作.序列器.视图_选定())
要做到这一点,我需要覆盖上下文,并告诉脚本它必须在序列器区域运行该命令,如果没有,它将给予:

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

...当然,只是设置:

bpy.context.area.ui_type = 'SEQUENCE_EDITOR'

什么也不做,但我又一次完全不知道该怎么做,任何帮助都将是非常感激的。

yqlxgs2m

yqlxgs2m1#

以下是正确的上下文覆盖:

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

相关问题