I am newbie to Blender scripting, but I am trying to make very simple Addon with the help of the YT tutorial that looks like this but it is giving me error that something is wrong, tho there is no error message in the console window.

The script should appear as a menu item inside OBJECT -> APPLY, and should just apply all the active modifiers in all selected objects. the script of the Addon looks like this:

bl_info = {
"name": "Apply Modifiers In Selected",
"author": "Anonymous",
"version": (1, 0),
"blender": (2, 90, 1),
"location": "View3D > Object > Apply > Modifiers In Selected",
"description": "Applies all the modifier in selected objects",
"warning": "",
"doc_url": "",
"category": "Object Apply",
}

import bpy
from bpy.types import (
Operator,
Panel,
PropertyGroup,
)

class OBJECT_OT_applymodifiersinselected(Operator):
bl_label = "Apply Modifiers In Selected"
bl_idname = "object.apply.modifiersinselected"
bl_description = "Applies all the modifier in selected objects"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_options = {'REGISTER', 'UNDO'}

def execute (self, context):

for ob in bpy.context.selected_objects:
bpy.context.view_layer.objects.active = ob
for name in [m.name for m in ob.modifiers]:
modifier = ob.modifiers[name]
if modifier.show_viewport:
bpy.ops.object.modifier_apply( modifier = name )

return {'FINISHED'}

self.layout.operator(OBJECT_OT_applymodifiersinselected.bl_idname)

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

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

if __name__ == "__main__":
register()


Can anyone, please, tell me what is wrong with the code?

The bl_idname is not allowed to contain more than one dot. The error message is:

Traceback (most recent call last):
File "\Text", line 52, in <module>
File "\Text", line 44, in register
RuntimeError: Error: Registering operator class: 'OBJECT_OT_applymodifiersinselected', invalid bl_idname 'object.apply.modifiersinselected', must contain 1 '.' character


This message can be seen when starting Blender from the terminal on Linux, macOS and Windows. On Windows you can also use Window > Toggle System Console.

In order to fix this pick a different bl_idname, for example:

 bl_idname = "object.apply_modifiers_in_selected"

• great, works now! BTW is there a way how to tell the Blender in what position in the submenu it should appear? Right now it is at the very end at the bottom - can I move it to some more elevated position and even add a separator line? – qraqatit Oct 29 '20 at 21:35
• You can't set the order as far as I'm aware. – Robert Gützkow Oct 29 '20 at 21:45