3
$\begingroup$

I have a simple script:

import bpy
from bpy.types import Panel,Operator

class MarkerAdd(Operator):
    bl_idname = 'marker.add'
    bl_label = 'Add Marker'
    def execute(self,context):
        bpy.ops.object.empty_add(type='PLAIN_AXES',radius=0.5,location=context.scene.cursor_location)
        return '{FINISHED}'

class AddObject(bpy.types.Panel):
    bl_label = "Add Object"
    bl_idname = "add_object"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"
    def draw(self, context):
        layout = self.layout
        scn = context.scene
        row = layout.row()
        row.operator('marker.add')

def register():
    bpy.utils.register_class(AddObject)
    bpy.utils.register_class(MarkerAdd)
def unregister():
    bpy.utils.unregister_class(AddObject)
    bpy.utils.unregister_class(MarkerAdd)


if __name__ == "__main__":
    register()

Which seems to work, but after pressing the button, a huge error appears:

RuntimeError: class MARKER_OT_add, function execute: incompatible return value , str(, Function.result expected a set, not a NoneType)

which I have no idea why. Is the execute function from MarkerAdd operator supposed to have a different result type? It does not matter whether I put there '{FINISHED}' or not.

$\endgroup$

1 Answer 1

5
$\begingroup$

OK, I realized that I made a typo/mistake. In the MarkerAdd operator, in the function execute I've put

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

which is a string, while it should be a Set:

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

Notice apostrophes. That simple mistake caused me to get lost in and I waste hours trying to understand what's wrong. I hope somebody could avoid similar mistake.

$\endgroup$
1
  • $\begingroup$ this error can also arise if u dont have return statement atol just like me $\endgroup$ Commented Mar 26, 2021 at 8:53

You must log in to answer this question.

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