Reputation: 1
i add button to top of the bar but two buttons are added. how can i fix this problem d
class ExportAll(bpy.types.Menu):
bl_label = "ExportAll"
bl_idname = "OBJECT_MT_simple_custom_menu"
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
row.operator("mesh.primitive_cube_add")
def draw_btn(self, context):
layout = self.layout
row = layout.row(align=True)
row.operator('mesh.primitive_cube_add',text="CUP",icon="IPO_EXPO")
def register():
bpy.utils.register_class(ExportAll)
bpy.types.TOPBAR_HT_upper_bar.append(draw_btn)
def unregister():
bpy.utils.unregister_class(ExportAll)
bpy.types.TOPBAR_HT_upper_bar.remove(draw_btn)
if __name__ == "__main__":
register()
Upvotes: 0
Views: 1823
Reputation: 96
UPDATED: TOPBAR_HT_upper_bar has two functions, draw_left and draw_right, and both may be called to draw menus. (see 2.90\script\startup\bl_ui\space_topbar.py, depending on your installation.) That means there are two panes and append is applied for both panes.
I got what you may have expected with the following code.
import bpy
class ExportAll(bpy.types.Menu):
bl_label = "ExportAll"
bl_idname = "OBJECT_MT_simple_custom_menu"
def draw(self, context):
self.layout.operator("mesh.primitive_cube_add",
text = "CUP",
icon = "IPO_EXPO")
def draw_btn(self, context):
draw_btn.f(self, context)
self.layout.menu(ExportAll.bl_idname, text = ExportAll.bl_label)
draw_btn.f = bpy.types.TOPBAR_HT_upper_bar.draw_right
def register():
bpy.utils.register_class(ExportAll)
bpy.types.TOPBAR_HT_upper_bar.draw_right = draw_btn
def unregister():
bpy.utils.unregister_class(ExportAll)
bpy.types.TOPBAR_HT_upper_bar.draw_right = draw_btn.f
if __name__ == "__main__":
register()
This link gave me a clue.
Upvotes: 1