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)
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.
#-*- 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
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.
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/
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!