0
$\begingroup$

I'm getting an error when trying to register a class. I'm sure it's something silly, but tried google, looking at templates and looking at the manual without luck. Here's the code:

import bpy



class MESH_OT_L(bpy.types.Operator):
    bl_idname = "mesh.L"
    bl_label = "delSplitNormals"
    bl_options = {"REGISTER", "UNDO"}
        
    
    def execute(self, context):
        
        selection = bpy.context.selected_objects

        for o in selection:
            bpy.context.view_layer.objects.active = o
            bpy.ops.mesh.customdata_custom_splitnormals_clear()
            
class VIEW3D_PT_dansTools(bpy.types.Panel):
    bl_label = "L"
    bl_category = "L"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    
    def draw(self, context):
        self.layout.operator('mesh.L')
        
def register():
    bpy.utils.register_class(MESH_OT_L)
    bpy.utils.register_class(VIEW3D_PT_dansTools)

    


def unregister():
    bpy.utils.unregister_class(MESH_OT_L)
    bpy.utils.unregister_class(VIEW3D_PT_dansTools)


if __name__ == "__main__":
    register()

Anyone any ideas?

Error in console

RuntimeError: Error: Registering operator class: 'MESH_OT_L', invalid bl_idname 'mesh.L', at position 5
$\endgroup$
2
  • $\begingroup$ What error? And your bl_idname seems to be not correct format. python - bl_idname requirements for 2.80 $\endgroup$
    – HikariTW
    Sep 27 '20 at 0:26
  • $\begingroup$ Also execute(self, context): in the Blender Operator subclass must return {'FINISHED'} or {'CANCELLED'} in the end - otherwise you get another Error trying to launch it $\endgroup$ Sep 28 '20 at 13:05
2
$\begingroup$

The bl_idname of MESH_OT_L should be lower case and one dot only, which is: mesh.l.


You need to follow the naming convention that Blender API required. It is kind of meta type that Blender used to organize the components that addon gonna registered.

And also you should use MESH_OT_L.bl_idname in your panel for clearance and flexible to change your bl_idname since it will warn you if MESH_OT_L is not found or missing bl_idname.

It is surely included in the page that you point out: Reference/Release Notes/2.80/Python API/Addons - Blender Developer Wiki

But it is not that clear why should lower case id been used (it is a former convention rather than 2.80 change)

$\endgroup$
2
  • $\begingroup$ I see, thanks! Looks like I need some more time with the manual and getting used to the conventions. $\endgroup$
    – danulrich
    Sep 27 '20 at 1:52
  • $\begingroup$ It could be confusing at the first time, manual didn't "strictly" list out the convention and give more valid and invalid example. $\endgroup$
    – HikariTW
    Sep 27 '20 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.