[Bf-committers] SystemError when using simple mesh commands in scripts started from the command line...

Martin Poirier theeth at yahoo.com
Fri Nov 6 15:57:22 CET 2009

--- On Fri, 11/6/09, Dietrich Bollmann <diresu at web.de> wrote:

> From: Dietrich Bollmann <diresu at web.de>
> Subject: [Bf-committers] SystemError when using simple mesh commands in scripts started from the command line...
> To: bf-committers at blender.org
> Received: Friday, November 6, 2009, 9:10 AM
> Hi,
> The following simple script doesn't work when used from the
> command
> line:
> ---
> import bpy
> bpy.ops.mesh.primitive_cube_add()
> ---
> Here the error message:
> ---
> blender -P /tmp/cube.py
> found bundled
> python:
> /home/dietrich/blendev/bazaar/blender/working/trunk/install/linux2/.blender/python
> Traceback (most recent call last):
>   File "/tmp/cube.py", line 2, in <module>
>     bpy.ops.mesh.primitive_cube_add()
>   File
> "/home/dietrich/blendev/bazaar/blender/working/trunk/blender/release/scripts/modules/bpy_ops.py",
> line 172, in __call__
>     return op_call(self.idname(), C_dict, kw)
> SystemError: bpy.__ops__.call: operator poll() function
> failed, context
> is incorrect
> *bpy stats* - tot exec: 78,  tot run: 0.0132sec, 
> average run:
> 0.000170sec,  tot usage 0.5393%
> Blender quit
> ---
> Should I file a bug report - or is this error caused by
> myself
> misunderstanding the command?

There might be a bit of both, but the are definitely some bugs in the API.

First, the context parameter passed to the operator call (like 'INVOKE_AREA', 'EXEC_SCREEN', ...) is only used for the calling function, not for the polling function.

So if the poll function requires a specific context, it will never work correctly when called from the command line.

That can be fixed by forcing a proper context like this:

import bpy
bpy.ops.mesh.primitive_cube_add("EXEC_AREA", {"scene": bpy.data.scenes[0]})

But then the operator fails silently (fun) because there is no window defined in the context (null check in wm_operator_call_internal) and that cannot be overwritten in Python (CTX_wm_window accesses the windowmanager directly, it doesn't try a lookup).
I'm not sure if that's NULL because the command line script is run before the wm is initialized or because it's using a fake python context (probably the former).

That also means running operators when blender is in background mode with always fail.

So yeah, in conclusion, the API is nowhere near ready and still has serious problems.

As a side note, it would be nice if polling errors could tell what's wrong with the current context.


Looking for the perfect gift? Give the gift of Flickr! 


More information about the Bf-committers mailing list