Discussion:
[Bf-python] finding correct operator poll context
Bassam Kurdali
2013-06-14 20:18:41 UTC
Permalink
Hi folks,
when running a script recently I received the error:
RuntimeError: Operator bpy.ops.wm.quit_blender.poll() failed, context is
incorrect

Here I would like to override the context and satisfy the operator,
however:
I don't know what is the failing check, and I don't even know where to
look.

So is there any wisdom as to finding this out?
a- for python operators,
b- for c operators ?

Is this possible to include in the operator docs, or would it be two
big?
cheers,
Bassam
Dima Glibitsky
2013-06-14 20:24:00 UTC
Permalink
As far as I know, there's no other way than to look at the operator's
source code... Though maybe some operators have the requirements
explained in their poll()'s docstring?
Post by Bassam Kurdali
Hi folks,
RuntimeError: Operator bpy.ops.wm.quit_blender.poll() failed, context is
incorrect
Here I would like to override the context and satisfy the operator,
I don't know what is the failing check, and I don't even know where to
look.
So is there any wisdom as to finding this out?
a- for python operators,
b- for c operators ?
Is this possible to include in the operator docs, or would it be two
big?
cheers,
Bassam
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python
Bassam Kurdali
2013-06-14 21:09:25 UTC
Permalink
Post by Dima Glibitsky
As far as I know, there's no other way than to look at the operator's
source code...
In the case of the python operators, I can find the code, but what about
the C code? are operators all together in one file, or scattered in
various modules?
Post by Dima Glibitsky
Though maybe some operators have the requirements
explained in their poll()'s docstring?
I think some might, but as a rule they don't. It's often possible to
figure it out (i.e. if you need an active object, or mode, or the right
space), but sometimes not (for instance, in what context should quit()
refuse to quit?)
Adhi Hargo
2013-06-14 22:43:01 UTC
Permalink
I found related functions in
source/blender/windowmanager/intern/wm_operators.c. The polling
function, WM_operator_winactive, only returns false when there's no
active window (bpy.context.window).

Maybe the script is ran UI-less?

A bpy operator's C functions can be scattered in some files (usually
they're not), but there's a Python interface function where they're
all presented as Python methods, so it shouldn't be hard to find all C
functions related to a Python operator. TAGS file
(etags/ctags-generated) or find+grep is really handy for this purpose.
--
- Adhi Hargo
Loading...