Blender 2.8 - Add view 3d menu

I’m trying to append a new menu in the 3dView header with no success. Any idea ?

maquette

import bpy

class VIEW3D_MT_menu(bpy.types.Menu):
    bl_label = "Test"

    def draw(self, context):
        self.layout.operator("mesh.primitive_monkey_add")

def addmenu_callback(self, context):
    self.layout.menu("VIEW3D_MT_menu")


def register():
    bpy.utils.register_class(VIEW3D_MT_menu)
    bpy.types.VIEW3D_MT_editor_menus.append(addmenu_callback)
    #bpy.types.VIEW3D_HT_header.append(addmenu_callback)  

def unregister():
    bpy.types.VIEW3D_MT_editor_menus.remove(addmenu_callback)
    #bpy.types.VIEW3D_HT_header.remove(addmenu_callback)  
    bpy.utils.register_class(VIEW3D_MT_menu)


if __name__ == "__main__":
	register()
2 Likes

What you have works. It places it after the Shading overlays. Append places at the end and prepend places at the beginning. As far as trying to get it in a specific location. The only way to prolly do that is edit the main .py file.

import bpy

class VIEW3D_MT_menu(bpy.types.Menu):
    bl_label = "Test"

    def draw(self, context):
        self.layout.operator("mesh.primitive_monkey_add")

def addmenu_callback(self, context):
    self.layout.menu("VIEW3D_MT_menu")


def register():
    bpy.utils.register_class(VIEW3D_MT_menu)
    bpy.types.VIEW3D_HT_header.append(addmenu_callback)  

def unregister():
    bpy.types.VIEW3D_HT_header.remove(addmenu_callback)  
    bpy.utils.unregister_class(VIEW3D_MT_menu)


if __name__ == "__main__":
	register()
1 Like

Thank you for the answer, I’ve also noticed that appending to VIEW3D_HT_header class works, but i don’t undersand why it does not works for VIEW3D_MT_editor_menus class. This one inherit from bpy.types.Menu and embed others menu in it’s layout; maybe the append functionnality is just not implemented for this bpy type, anyone can confirm this ?

1 Like

OK, check this out. It seems to get added ,but for some reason it doesn’t show in 3D View.

Run this first

import bpy


class HelloWorldPanel(bpy.types.Panel):
	"""Creates a Panel in the Object properties window"""
	bl_label = "Hello World Panel"
	bl_idname = "OBJECT_PT_hello"
	bl_space_type = 'PROPERTIES'
	bl_region_type = 'WINDOW'
	bl_context = "object"

	def draw(self, context):
		layout = self.layout

		row = layout.row()
		row.menu("VIEW3D_MT_editor_menus")


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


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


if __name__ == "__main__":
	register()

then this

import bpy

class VIEW3D_MT_menu(bpy.types.Menu):
	bl_label = "Test"

	def draw(self, context):
		self.layout.operator("mesh.primitive_monkey_add")

		
def addmenu_callback(self, context):	
	self.layout.menu("VIEW3D_MT_menu")    
	


def register():
	bpy.utils.register_class(VIEW3D_MT_menu)
	bpy.types.VIEW3D_MT_editor_menus.append(addmenu_callback)  

def unregister():
	bpy.types.VIEW3D_MT_editor_menus.remove(addmenu_callback)  
	bpy.utils.unregister_class(VIEW3D_MT_menu)


if __name__ == "__main__":
	register()
1 Like

Thanks for the investigation, I openned a new issue on the bugs tracker : https://developer.blender.org/T58937