【问题标题】:Blender 3D ui add buttonBlender 3D ui 添加按钮
【发布时间】:2020-12-28 08:37:31
【问题描述】:

我将按钮添加到栏的顶部,但添加了两个按钮。我该如何解决这个问题d

enter image description here

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()

【问题讨论】:

    标签: python button blender


    【解决方案1】:

    更新: TOPBAR_HT_upper_bar 有两个函数draw_left 和draw_right,都可以调用来绘制菜单。 (请参阅 2.90\script\startup\bl_ui\space_topbar.py,具体取决于您的安装。) 这意味着有两个窗格,并且对两个窗格都应用了追加。

    我得到了您对以下代码的期望。

    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 给了我一个线索。

    【讨论】:

    • 还是加了两个按钮
    • 告诉我你的操作系统和搅拌机版本
    • win10 - 搅拌机 2.90
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-02
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多