Bundle Contexts for Panels and Tabs

Can you use a Bundle Context to have a tab only show when a certain type of document is active?
For instance, show a set of tools only when “context: doc-family”?
I figured out how to make it disable a button, but I had to put the bundle.yaml under the .pushbutton.
Is there a way to just make the panel disappear if the document is not a family doc?
Is there another way to do this other than the Bundle contexts?


This is something I was looking into as well. From what I can see the API does not provide an easy way to achieve this, but I did find a work around using a ViewActivated handler and the AdWindows.dll which provides access to the tabs inside the ribbon. There may be a better method to achieve this, but from my limited testing this works well enough.
To use this all you need to do is add the names of the specific tabs you want hidden and add it into your startup.py script inside the root directory of your pyRevit extension.

To clarify, this will also disable any commands contained within that tab while it’s not visible.

from pyrevit.api import AdWindows

class FamilyDocumentTabHider:
    def __init__(self, uiapp):
        self.hidden_tabs = ["Tab Name"]  # put names of tabs you want hidden outside of family documents
        self.AdWindows = AdWindows
        self.previous_doc = None

    def toggle_visibility(self, doc):
        if self.previous_doc is None:
            self.previous_doc = doc.IsFamilyDocument
            return not doc.IsFamilyDocument
        elif doc.IsFamilyDocument != self.previous_doc:
            self.previous_doc = doc.IsFamilyDocument
            return True
            return False

    def get_tabs(self):
        return [tab for tab in self.AdWindows.ComponentManager.Ribbon.Tabs if tab.Title in self.hidden_tabs]

    def toggle_tabs(self, toggle):
        for tab in self.get_tabs():
            tab.IsVisible = toggle

    def register(self, uiapp):
        uiapp.ViewActivated += self.view_activated_handler

    def view_activated_handler(self, sender, args):
        doc = args.Document
        if self.toggle_visibility(doc):

1 Like