Hide PyRevit Core on Startup

Hi,

Just getting my head around pyRevit, reasonably comfortable in Python and the Revit API.

I am trying to hide the PyCore toolbar, so we just show our custom toolbar.

There was only 1 reference I could find on the forum:

My attempt failed because I couldn’t return the UIApp, I believe when replicating this sample code:

I also struggled to dig and find the exact method that the minify tab is using on github, it’s being loaded in from ‘Script’ which obviously returns a lot of results!

I have found some other resources, with an example of a startup file and the doc opening event (which I hope to swap out for the AppInitialised eventually) and setting the Tab.Visible = False.

I don’t have any errors now, the py is firing, because I get the form popup, but it’s not hiding the Tab!

Any suggestions gratefully received!

Mark

from pyrevit import HOST_APP, framework
from pyrevit import revit, DB

from pyrevit import forms
from pyrevit import script
from pyrevit.coreutils import ribbon
from pyrevit.loader import sessionmgr
from pyrevit import EXEC_PARAMS

name = 'pyrevit_tab'

print(name)

from Autodesk.Revit.UI import UIApplication

def hide_tab(name):
    tab = UIApplication.GetRibbonPanels(name)
    tab.Visible = False
    print(tab)

# define event handler
def docopen_eventhandler(sender, args):
    forms.alert('Document Opened: {}'.format(args.PathName))
    hide_tab(config)    

# add to DocumentOpening
# type is EventHandler[DocumentOpeningEventArgs] so create that correctly
HOST_APP.app.DocumentOpening += framework.EventHandler[DB.Events.DocumentOpeningEventArgs](docopen_eventhandler)

Hello @Mark_Ackerley

I use two hook scripts to hide the pyrevit tab on every opening or creation of a file. So this also runs when creating or opening a family, which is not perfect but it works. I don´t use a startup.py for this because I can not control the c drive of all users, thats why i like this method more because i still can control it when it is lying on the server.

image

#-*- coding: utf-8 -*-
import clr
clr.AddReference('AdWindows')
clr.AddReference('RevitAPI')
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.DB import*
import Autodesk.Windows as AdWindows

doc = __eventargs__.Document
app = __revit__

Ribbon = AdWindows.ComponentManager.Ribbon
Tabs = Ribbon.Tabs

names=[]
for tab in Tabs:
    Id = tab.Id
    Name = tab.AutomationName
    visible = tab.IsVisible
    names.append(Name)
    if Name == "pyRevit":
        pyRevit = tab

pyRevit.IsVisible = False
3 Likes

OOoh… ! That worked! Fantastic! Thank you so much!

An here is a pushbutton that hides/unhides the tab so the users can show the tab if they want.

#-*- coding: utf-8 -*-
import clr
clr.AddReference('AdWindows')
clr.AddReference('RevitAPI')
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.DB import*
import Autodesk.Windows as AdWindows

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
app = __revit__.Application

Ribbon = AdWindows.ComponentManager.Ribbon
Tabs = Ribbon.Tabs

names=[]
for tab in Tabs:
    Id = tab.Id
    Name = tab.AutomationName
    visible = tab.IsVisible
    names.append(Name)
    if Name == "pyRevit":
        pyRevit = tab
        
if pyRevit.IsVisible:  
    pyRevit.IsVisible = False
    
else:  
    pyRevit.IsVisible = True
3 Likes

If you wouldn’t mind humouring me a little…

So the line doc = __eventargs__.Document corresponds to the document opened event…
DocumentOpenedEventArgs
could you point me to the documentation where the pyRevit ‘shorthand’ is listed? Apologies if it is obvious, I’ve looked in Notion and and Github.

Thanks,

Mark

At hook scripts the event handler is determined by the file name only.

To get the current document inside a hook script you just have to use another method, the method i use in the pushbutton would not work in a hook script.

Sorry I have no link for you, I only look in my code^^

I hope soon I will find time to finish this page that is currently under construction, there will be many pyRevit code! https://www.revitpythondocs.com/

1 Like

Ooh sorry for the lack of understanding, I saw that your file wasn’t exactly the same as the hook name and presumed something else was going on. So as long as there is ‘doc-opened’ at the end of the file name we are good!

Thanks again,

Mark

I hide the pyRevit tab using standard pyRevit tools and its settings in “pyRevit_config.ini”

pyrevit configs pyRevitCore.extension:disabled true
pyrevit configs pyRevitCore.extension:private_repo true
pyrevit configs pyRevitCore.extension:username ""
pyrevit configs pyRevitCore.extension:password ""
4 Likes