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

Dietrich Bollmann diresu at web.de
Sat Nov 7 13:45:32 CET 2009


Hi Martin and Roger,

> --- On Fri, 11/6/09, Roger Wickes <rogerwickes at yahoo.com> wrote:
> 
> > i think OP just wanted to add a cube to the scene....

That's it :)

> On Fri, 2009-11-06 at 09:39 -0800, Martin Poirier wrote:
> 
> I know, my point is you can't do that using command line scripts.
> Which explains the error he was getting.

Which is interesting also as it explains that the API is still work in
progress and that currently it is not possible to create meshes from
scripts executed from the command line...  

So it is not my code (at least not entirely) but the state of the API
and for the moment it is just to early for this kind of scripts...

I am also happy to now understand somehow what exactly a "context" is :)

I understood that the context depends on the cursor positioned somewhere
on the GUI; now I know also that the context consists in the
specification of a scene and some variable specifying the current window
and that the first of these can be set from Python and the second not
(...the latter one being the reason why it is currently impossible to
create meshes from scripts executed from the command line.)

I understand that the scene has to be set (the syntax could be nicer
though) and I suppose that the window is necessary for polling the
current windows event queue before executing the command when creating
meshes from the GUI.

If this intuition should be right it probably doesn't make sense to poll
any window queue when executing code from a script and it should be
enough to skip the polling when the window context is not set at the
place of throwing an error?

Regards, Dietrich


> On Fri, 2009-11-06 at 09:39 -0800, Martin Poirier wrote:
> I know, my point is you can't do that using command line scripts.
> Which explains the error he was getting.
> 
> Martin
> 
> --- On Fri, 11/6/09, Roger Wickes <rogerwickes at yahoo.com> wrote:
> 
> > i think OP just wanted to add a cube
> > to the scene....
> > 
> > 
> > --- On Fri, 11/6/09, Dietrich Bollmann <diresu at web.de>
> > wrote:
> > 
> > > From: Dietrich Bollmann <diresu at web.de>
> > > 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.
> > 
> > Martin




More information about the Bf-committers mailing list