2
$\begingroup$

The info context menu shows me the below code, but if I copypasted the code with import bpy, it doesn't work.

bpy.ops.sequencer.effect_strip_add(type='TEXT', frame_start=1, frame_end=26, channel=1)

The error is

Traceback (most recent call last):
  File "/Text", line 3, in <module>
NameError: name 'override' is not defined
Error: Python script failed, check the message in the system console


$\endgroup$
2
  • $\begingroup$ what does 'doesn't work' mean? Generates an error? If so, please include the error in your quesiton. If the error message ends 'context is incorrect', you need to add a context override $\endgroup$ May 4 at 17:39
  • $\begingroup$ It was that. updated $\endgroup$ May 5 at 4:57

1 Answer 1

2
$\begingroup$

Most bpy.ops need a context override to be executed from the python console. In your case, you need to override the area and region so that the op will know to use the video sequence editor's window as its context.

Here is code that you can cut and paste into the console that will do that.

areasVSE  = [area for area in bpy.context.window.screen.areas if area.type == 'SEQUENCE_EDITOR']
region   = [region for region in areasVSE[0].regions if region.type == 'WINDOW']
override = {
    'area'  : areasVSE[0],
    'region': region[0],
}

bpy.ops.sequencer.effect_strip_add(override, type='TEXT', frame_start=1, frame_end=26, channel=1)```

Note that this assumes that you have only one window open with the VSE. If you have more, it will pick the first one.

3.2 Update

Context overrides are deprecated in Blender 3.2 and are scheduled to be removed in Blender 3.3 The replacement is temp_override. The manual has examples of how to use the new function.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.