I want to add a button to the “TOPBAR_MT_render” menu (basically the menu in the top bar were you click to render.) The button should look like the Lock Interface one, so it should have a checkbox.
Would be nice if you could help me with this.
I want to add a button to the “TOPBAR_MT_render” menu (basically the menu in the top bar were you click to render.) The button should look like the Lock Interface one, so it should have a checkbox.
Would be nice if you could help me with this.
Append or Prepend a draw method to menu class.
Very closely related How to add a checkbox to a pie menu?
import bpy
def draw(self, context):
layout = self.layout
scene = context.scene
render = scene.render
layout.prop(render, "use_lock_interface")
def register():
bpy.types.TOPBAR_MT_render.append(draw)
# make your unregister and remove draw
if __name__ == "__main__":
register()
TIP Turn on developer extras in user preferences and can right click to view source (Edit Source, as it opens in text editor.) of most UI elements.
Import bpy
class my_settings(bpy.types.PropertyGroup):
my_bool: bpy.props.BoolProperty(
name='Settings',
default=True
)
def draw(self, context):
layout = self.layout
rn_tool = context.scene.my_tool
row = layout.row()
row.prop(my_tool, "my_bool")
def register():
bpy.types.TOPBAR_MT_render.append(draw)
bpy.utils.register_class(my_settings)
bpy.types.Scene.my_tool = bpy.props.PointerProperty(type=my_settings)
def unregister():
bpy.types.TOPBAR_MT_render.remove(draw)
bpy.utils.unregister_class(my_settings)
del bpy.types.Scene.my_tool
if __name__ == '__main__':
register()