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

标签 python blender bpy

我寻求帮助,因为我真的不知道我必须为此做什么。我绞尽脑汁两天了,我不得不承认我就是不明白......

我需要一个脚本来将定序器中的 View 设置为 bpy.ops.sequencer.view_all() (或类似:bpy.ops.sequencer.view_selected())

为此,我需要覆盖上下文并告诉脚本它必须在定序器区域中运行该命令,如果没有,它将给出:

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'

..什么也不做 但我再次完全不知道该怎么做,任何帮助将不胜感激..

最佳答案

这是正确的上下文覆盖:

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

关于python - bpy.ops.sequencer.view_all() 轮询失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75193580/

相关文章:

python - 如何破解 blender 帮助按钮?

python - 需要在 blender 中自定义模型导出脚本

python - 导入错误 : No module named 'bpy'

python - blender 2.6 : Select object by name through Python

python 请求 POST cookie session

用于计算 : 1 + 2 + 4 + 8 + 16 + 32 + 64 + . ... + n 序列项之和的 Python 程序,其中 n 是输入

python - ModuleNotFoundError:没有名为 'pycaret.arules' 的模块

python - 导入错误 : No module named 'bottle' in PyCharm

python - Blender 卡住在 python 脚本中?