1
$\begingroup$

Can I somehow make the poll method of my operator sensitive to whether the operator is being invoked or executed?

Take for example:

from bpy.types import Operator
class TestOp(Operator):
    bl_idname = "test.test"
    bl_label = "Test operator"

    @classmethod
    def poll(self, context):
        return False

    def execute(self, c):
        print("Executed, just executing")

    def invoke(self, c, e):
        print("Invoked, taking user input")

I want to rework the poll method so that, when the operator is executed, it always returns True (run from scripts, etc.., assume parameters are set).

When invoked, the context has to fit in a way that the user is able to input the needed parameters. For the sake of the example, let's say we need an object with context.object.type == 'MESH' in context.mode == 'EDIT_MESH'.

Is there a way to determine the way the operator will be invoked inside its poll method?

$\endgroup$
1
  • $\begingroup$ I don't understand why you would need two different poll checks for a single operator. I suspect a flaw in your intended design. If really necessary, let invoke() or execute() return {'CANCELLED'} to abort. poll() is supposed to determine whether an operator is able to run at all, and shouldn't check for something that isn't decided yet (modal user input in invoke). $\endgroup$
    – CodeManX
    Aug 3, 2015 at 19:16

0

You must log in to answer this question.

Browse other questions tagged .