0
$\begingroup$

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()
$\endgroup$
  • $\begingroup$ As suggested here It's an operator not a tool setting class MESH_OT_toggle_automerge(bpy.types.Operator) and in layout its an operator not a separator ... use the new class name not the old layout.operarator(MESH_OT_toggle_automerge.bl_idname) The suggestion was to make this an edit to original question, not a new question. $\endgroup$ – batFINGER May 1 at 13:55
  • $\begingroup$ Apologies re confusion Notice on prior question @RayMairlot suggested making this a new question, via review. As mentioned above, I would recommend making it an edit to original. $\endgroup$ – batFINGER May 1 at 14:03
  • $\begingroup$ @batFINGER is correct. I couldn't seem to see the option to suggest making an edit to the question instead. $\endgroup$ – Ray Mairlot May 1 at 15:06

Your Answer

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

Browse other questions tagged or ask your own question.