This question follows: Blender 2.8 Python Addon: How to register a Button?
Late thanks dr.Sybren! I like your "Scripting for Artists". Could you explain what you mean by
"...class name should follow the bl_idname"?
I`m getting this error now:
bpy.utils.register_class(MESH_OT_toggle_automerge)
ValueError: register_class(...): expected a subclass of a registerable rna type
(ToolSettings does not support registration)
Here is my new version:
bl_info = {
"name": "Toggle Automerge",
"blender": (2, 80, 0),
'location': '(Edit mode) Mesh > Vertices > toggle_automerge',
"description": "Toggles Automerge on and off",
"category": "Mesh",
}
import bpy
def toggle_automerge(context):
ts = context.scene.tool_settings
ts.use_mesh_automerge = not ts.use_mesh_automerge
class MESH_OT_toggle_automerge(bpy.types.ToolSettings):
"""Toggle Automerge"""
bl_idname = "mesh.toggle_automerge"
bl_label = "Toggle Automerge"
bl_options = {'REGISTER'}
def execute(self, context):
toggle_automerge(self, context)
return {'FINISHED'}
def toggle_automerge_button(self, context):
# Only draw this Specials menu item when the vertex or edge selection modes are active.
selectMode = context.tool_settings.mesh_select_mode
if selectMode[0] or selectMode[1]:
self.layout.separator(
ToggleAutomergeOperator.bl_idname,
text="Toggle Automerge",
icon='PLUGIN')
# Registration
def register():
bpy.utils.register_class(MESH_OT_toggle_automerge)
# Add the tool to the Mesh > Vertices menu
bpy.types.VIEW3D_MT_edit_mesh_vertices.append(toggle_automerge_button)
bpy.types.VIEW3D_MT_edit_mesh_context_menu.append(toggle_automerge_button)
def unregister():
bpy.utils.unregister_class(MESH_OT_toggle_automerge)
# Add the tool to the Mesh > Vertices menu.
bpy.types.VIEW3D_MT_edit_mesh_vertices.remove(toggle_automerge_button)
bpy.types.VIEW3D_MT_edit_mesh_context_menu.remove(toggle_automerge_button)
if __name__ == "__main__":
register()
class MESH_OT_toggle_automerge(bpy.types.Operator)
and in layout its an operator not a separator ... use the new class name not the oldlayout.operarator(MESH_OT_toggle_automerge.bl_idname)
The suggestion was to make this an edit to original question, not a new question. $\endgroup$