0

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.

Image which shows what I mean

Would be nice if you could help me with this.

  • yeah i mean a BoolProperty then. I just want that the user can activate/deactivate a function of an addon. – MatFynus Mar 17 '20 at 10:00

2 Answers2

1

Append or Prepend a draw method to menu class.

Very closely related How to add a checkbox to a pie menu?

enter image description here

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.

Add toggle hotkey to custom checkbox

batFINGER
  • 84,216
  • 10
  • 108
  • 233
  • Problem is, that I don't want it to be copied. I want a whole new Boolproperty. Which does other stuff then the "Lock Interface" one... Do you know how this works? – MatFynus Mar 17 '20 at 10:40
  • You're kidding? and Yes I know how this works. IMO this answers your question: ie how to add an item to render menu that looks like the lock interface. Bit tongue in cheek, I added a twin. There are numerous questions on how to create a boolean property on BSE. The linked question if you even bothered to open it describes how to add a bool property. Please make an effort to search for answers and not want more than you asked for., which becomes a problem. – batFINGER Mar 17 '20 at 10:46
  • Got it to work. Thanks – MatFynus Mar 17 '20 at 11:15
0
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()

  • 2
    Cool, do you mind adding any explanation? How this site works: https://blender.stackexchange.com/tour – brockmann Mar 17 '20 at 11:56