3
$\begingroup$

I have created a custom panel and when N is pressed on the keyboard in 3d view we get the Sidebar with the Item tab opened by default, but I don't want that. I have also added an operator that does the same as N but I want to add one more thing that I could not find.

When someone presses N or executes my operator by pressing Shift+N it should open the Sidebar tab with my add-on.

import bpy


class MY_PT_PANEL(bpy.types.Panel):
    bl_label = "My Addon"
    bl_idname = "MY_PT_TAB"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "MyTab"

    def draw(self, context):
        layout = self.layout
        layout.label(text='Welcome to my addon',icon='FORWARD')

class MY_OT_OPERATOR(bpy.types.Operator):
    bl_idname='addon.open_sidebar'
    bl_label = 'Open SideBar'

    def execute(self,context):
        areas = bpy.context.screen.areas
        view_3d = None
        for area in areas:
            if area.type == 'VIEW_3D':
                view_3d = area

        space = view_3d.spaces[0]
        space.show_gizmo = False
        space.show_region_ui = True

        return {'FINISHED'}

addon_keymap = []

def register():
    bpy.utils.register_class(MY_PT_PANEL)
    bpy.utils.register_class(MY_OT_OPERATOR)

    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    km = kc.keymaps.new('3D View', space_type = 'VIEW_3D')
    kmi = km.keymap_items.new('addon.open_sidebar','N','PRESS',shift=True)

    addon_keymap.append((km,kmi))

def unregister():
    bpy.utils.unregister_class(MY_PT_PANEL)
    bpy.utils.unregister_class(MY_OT_OPERATOR)

    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    for km, kmi in addon_keymap:
        km.keymap_items.remove(kmi)
    addon_keymap.clear()    

if __name__ == "__main__":
    register()
```
$\endgroup$
13
  • $\begingroup$ Hello! What exactly do you mean by "open an addon" ? $\endgroup$
    – Gorgious
    Commented Feb 9, 2023 at 15:05
  • $\begingroup$ I mean whenever we press N it opens the Item tab which I don't. I should open another tab like View or Tool or my addon. $\endgroup$
    – Muzammil
    Commented Feb 9, 2023 at 15:23
  • 1
    $\begingroup$ In this case this and this should answer your question $\endgroup$
    – Gorgious
    Commented Feb 9, 2023 at 16:32
  • $\begingroup$ no, I'm not looking for this. $\endgroup$
    – Muzammil
    Commented Feb 9, 2023 at 16:43
  • 1
    $\begingroup$ Seems like it is really impossible to change the active Sidebar tab from Blender's Python API. $\endgroup$ Commented Feb 22, 2023 at 8:44

0

You must log in to answer this question.

Browse other questions tagged .