I want to add music via python. I tried:

bpy.ops.sequencer.sound_strip_add(bpy.ops.sequencer.sound_strip_add(filepath="//mymusic.mp3", frame_start=0, channel=1)

but somehow it gives me the error:

drop file blabla
Traceback (most recent call last):
  File "blabla", line 60, in <module>
  File "C:\Program Files\Blender Foundation\Blender\2.77\scripts\modules\bpy\ops.py", line 189, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.sequencer.sound_strip_add.poll() failed, context is incorrect

Error: Python script fail, look in the console for now...

Any ideas?

  • 1
    $\begingroup$ Have a look at blender.stackexchange.com/questions/6101/… In this case you need to be in the 'SEQUENCE_EDITOR' space. $\endgroup$
    – batFINGER
    Commented Sep 27, 2016 at 18:43
  • $\begingroup$ since i dont really want to go there and just add the sound is there no workaround? or can i switch to the editor space with python and then back? $\endgroup$
    – froggyman
    Commented Sep 27, 2016 at 18:44
  • $\begingroup$ scene.sequence_editor.sequences.new_sound(name, filepath, channel, frame_start) $\endgroup$
    – batFINGER
    Commented Sep 27, 2016 at 18:47
  • $\begingroup$ NameError: name 'scene' is not defined $\endgroup$
    – froggyman
    Commented Sep 27, 2016 at 18:50
  • $\begingroup$ related: blender.stackexchange.com/questions/62163/… $\endgroup$
    – zeffii
    Commented Sep 28, 2016 at 7:05

1 Answer 1

import bpy
from bpy import context

scene = context.scene 

if not scene.sequence_editor:

#Sequences.new_sound(name, filepath, channel, frame_start)    
soundstrip = scene.sequence_editor.sequences.new_sound("toad", "~/toad_sound.mp3", 3, 1)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .