# Access a property in python from a menu

I tried to answer a question on blenderartists from what I already know, and then it was pointed out to me that I should be able to use the property directly in the panel menu instead of creating the operator for it outside the menu like I did here:

import bpy

class AutoMergeBool(bpy.types.Operator):
"""Automerge Toggle"""
bl_idname = "mesh.automerge_toggle"
bl_label = "Automerge Toggle Operator"

@classmethod
def poll(cls, context):
return context.active_object is not None

def execute(self, context):
#main(context)
merge = bpy.context.scene.tool_settings

if merge.use_mesh_automerge != True:
merge.use_mesh_automerge = True
else:
merge.use_mesh_automerge = False
return {'FINISHED'}

def draw(self, context):

self.layout.operator("mesh.automerge_toggle")

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

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

if __name__ == "__main__":
register()


Can anyone give me a single line example of how the property should be accessed in the layout so that it results in the bool? I already tried searching here and elsewhere and haven't found anything that works.

Instead of adding a layout.operator you would add a layout.prop, which would look like this:
self.layout.prop(context.scene.tool_settings, "use_mesh_automerge")