3

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

Martynas Žiemys
  • 24,274
  • 2
  • 34
  • 77
Muzammil
  • 828
  • 2
  • 14
  • Hello! What exactly do you mean by "open an addon" ? – Gorgious Feb 09 '23 at 15:05
  • 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. – Muzammil Feb 09 '23 at 15:23
  • 1
    In this case this and this should answer your question – Gorgious Feb 09 '23 at 16:32
  • no, I'm not looking for this. – Muzammil Feb 09 '23 at 16:43
  • you want to open new window for your addon? – Karan Feb 09 '23 at 17:48
  • No, I mean when someone presses the N key it opens the Region UI with the Transform tab. I want to open another tab instead of Transform like View or Tool or my addon. – Muzammil Feb 10 '23 at 05:51
  • So you want to make another tab default to N but why? – Karan Feb 10 '23 at 16:22
  • Change you question title and description. – Karan Feb 10 '23 at 16:27
  • @Muzammil Your response was already given by @Gorgious... But you probably haven't even read the other threads. The Toolbar for the N shortcut is defined by bl_category. If you want a new tab with a name "MyTab", just add bl_category = "MyTab" to the attributes of your panel, and Blender will create a new tab for your Panel (or place your panel in another tab, if it already exists). – Secrop Feb 21 '23 at 21:43
  • Please read the question's description again. – Muzammil Feb 22 '23 at 06:18
  • Alright, I understand what you want, @Karan seems to have pinpointed the problem. I don't know if this is available to the python API unfortunately. I'm sorry to inform you that AFAIK this is not possible. See https://blender.stackexchange.com/questions/163360/is-it-possible-to-change-the-active-bl-category-with-python Unless you're willing to dive into the source code and build a custom version of Blender. – Gorgious Feb 22 '23 at 07:15
  • There is a hack, you have to get your addon tab position and simulate a click on it. – Karan Feb 22 '23 at 08:16
  • 1
    Seems like it is really impossible to change the active Sidebar tab from Blender's Python API. – Martynas Žiemys Feb 22 '23 at 08:44

0 Answers0