0
$\begingroup$

I want to add marker on a video clip ( Shift+F2 from homescreen and then select the video file).

This is my code:

import bpy 

result = [(.4, .4), (.5, .5)]

for (x, y) in result:
    bpy.ops.clip.add_marker(location=(0.0, 0.0))

The error I am getting:

Python: Traceback (most recent call last):
  File "/Text", line 6, in <module>
  File "/snap/blender/5234/4.2/scripts/modules/bpy/ops.py", line 109, in __call__
    ret = _op_call(self.idname_py(), kw)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    RuntimeError: Operator bpy.ops.clip.add_marker.poll() failed, context is incorrect

I need help to select the right context, that is the video file. Any help/ direction/ documentation would be appreciated.

$\endgroup$
1

1 Answer 1

0
$\begingroup$

You need to make sure script is either executed from Clip Editor (e.g. it's an operator located in Clip Editor UI) or override current context's area with CLIP_EDITOR.

import bpy
from typing import Any

context = bpy.context
assert context.screen


def get_area_context(area_type: str) -> dict[str, Any]:
    screens = list(bpy.data.screens)
    # Prioritize current screen.
    screens.sort(key=lambda x: x == context.screen, reverse=True)
    screen, fitting_area = None, None
    for screen in screens:
        for area in screen.areas:
            if area.type == area_type:
                return {"screen": screen, "area": area}

    assert False, "No clip editor area found."


result = [(0.4, 0.4), (0.5, 0.5)]

with context.temp_override(**get_area_context("CLIP_EDITOR")):
    for x, y in result:
        bpy.ops.clip.add_marker(location=(x, y))
```
$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.