0
$\begingroup$

i'm following a 2.79 blender python tutorial for beginners, under 2.83.2. i'm having trouble removing the poll from the classmethod. (is there a reason i shouldn't do that?) this works:

class MonkeyOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.make_monkey"
    bl_label = "Monkey Operator"

    @classmethod
    def poll(cls, context):
        return context.object is None

    def execute(self, context):
        main(context)
        return {'FINISHED'}


def register():
    bpy.utils.register_class(MonkeyOperator)


def unregister():
    bpy.utils.unregister_class(MonkeyOperator)


if __name__ == "__main__":
    register()

...

but if i comment out or delete the poll lines, it throws this error:

line 61, in register TypeError: expected Operator, MonkeyOperator class "execute" attribute to be a function, not a method

the execute is exactly the same as before. so... ???

$\endgroup$
1
  • $\begingroup$ I can not reproduce your error (btw: line 61 is not part of the code posted). In general I'd suggest to check/poll for Object Mode (if your goal is to add an object) or at least return True in case you need poll() method later on. $\endgroup$
    – brockmann
    Jul 17 '20 at 1:03
2
$\begingroup$

You would have to remove or comment out the method including the @classmethod decorator:

import bpy

class MonkeyOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.make_monkey"
    bl_label = "Monkey Operator"

    def execute(self, context):
        # do stuff
        return {'FINISHED'}

def register():
    bpy.utils.register_class(MonkeyOperator)

def unregister():
    bpy.utils.unregister_class(MonkeyOperator)


if __name__ == "__main__":
    register()

For multiline comments you can use triple-quoted strings:

'''
@classmethod
def poll(cls, context):
    return context.object is None
'''
$\endgroup$

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .