3
$\begingroup$

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?

$\endgroup$
  • 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 Sep 27 '16 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 Sep 27 '16 at 18:44
  • $\begingroup$ scene.sequence_editor.sequences.new_sound(name, filepath, channel, frame_start) $\endgroup$ – batFINGER Sep 27 '16 at 18:47
  • $\begingroup$ NameError: name 'scene' is not defined $\endgroup$ – froggyman Sep 27 '16 at 18:50
  • $\begingroup$ related: blender.stackexchange.com/questions/62163/… $\endgroup$ – zeffii Sep 28 '16 at 7:05
3
$\begingroup$
import bpy
from bpy import context

scene = context.scene 

if not scene.sequence_editor:
    scene.sequence_editor_create()

#Sequences.new_sound(name, filepath, channel, frame_start)    
soundstrip = scene.sequence_editor.sequences.new_sound("toad", "~/toad_sound.mp3", 3, 1)
$\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.