1
$\begingroup$

I'm trying to get a python based audio visualisation script to work in blender via command line interface. Here's the code myscript.py

When I run the following in blender 2.66 on Ubuntu 14.04

blender -b -noaudio -P myscript.py

I get the following error

File "/home/random9/myscript.py", line 66, in <module>
bpy.ops.anim.keyframe_insert_menu(type='Scaling')
File "/usr/share/blender/2.79/scripts/modules/bpy/ops.py", line 189, in __call__
ret = op_call(self.idname_py(), None, kw)

RuntimeError: Operator bpy.ops.anim.keyframe_insert_menu.poll() failed,
context is incorrect

in [line number 66]

bpy.ops.anim.keyframe_insert_menu(type='Scaling')

How do I resolve this error?

I've been going through the python scripting docs and it suggests that I should be able to figure out what context an operator needs simply by seeing how it’s used in Blender and thinking about what it does.

Any help is appreciated.

$\endgroup$
  • $\begingroup$ You can avoid the keyframe insert menu operator completely with context.object.keyframe_insert("scale", group="Scale") $\endgroup$ – batFINGER Oct 16 '17 at 10:56
  • 1
    $\begingroup$ blender.stackexchange.com/questions/2848/why-avoid-bpy-ops $\endgroup$ – Ray Mairlot Oct 16 '17 at 12:01
  • $\begingroup$ @batFINGER, however armature data objects have no keyframe_insert_menu method. $\endgroup$ – robit Apr 23 '19 at 7:25
  • 1
    $\begingroup$ You can avoid the keyframe insert menu operator completely with context.object.keyframe_insert("scale", group="Scale") $\endgroup$ – batFINGER Apr 23 '19 at 8:33
  • $\begingroup$ @batFINGER, thx. With your suggestion, I substitute bpy.ops.anim.keyframe_insert_menu(type='BUILTIN_KSI_VisualLocRotScale') with obj.keyframe_insert('location', group='Location'); obj.keyframe_insert('scale', group='Scale'); obj.keyframe_insert('rotation_quaternion', group='Rotation'), and everything works fine! $\endgroup$ – robit Apr 24 '19 at 2:10

Browse other questions tagged or ask your own question.