I made some code that needs to run on a hook (start-up, open doc or app-init all seem viable).
The script works when i test it from a PushButton, But it fails when run from a hookscript.
When run form a hook ( tried all 3 types) it doesn’t seems to find the button itself.
reflections on why this is?
# -*- coding: utf-8 -*-
# imports
# ===================================================
import os
from pyrevit import forms
from pyrevit.coreutils import ribbon
from logUtils import version_check
from dirUtils import ext_dir
# definitions
# ===================================================
def Updatebutton():
uptodate = version_check()
if uptodate == True:
icon_path = os.path.join(ext_dir(),'Tools.tab','Settings.panel','Update.PushButton','on.png')
ribbon.get_uibutton("Update").set_icon(icon_path)
if uptodate == False:
icon_path = os.path.join(ext_dir(),'Tools.tab','Settings.panel','Update.PushButton','off.png')
ribbon.get_uibutton("Update").set_icon(icon_path)
# Main
# ===================================================
if __name__ == '__main__':
# Set update button
Updatebutton()
I tried multiple configs and it seems that pyrevit is able to find the tabs and even the button.
But not the Methode for setting the icon in any hook configureation i tried.
Wierd thing is that in a statup.py script the button is not found on a reload it is (wich also trigger the startup script).
code: print(ribbon.get_uibutton("Update"))
When run from reload (in startup.py): Name: Update RevitAPIObject: <Autodesk.Revit.UI.PushButton object at 0x0000000000002093 [Autodesk.Revit.UI.PushButton]>
Hi @AlexanderVDB, the error you stated before is due to the get_ubutton not finding the button, and that’s exactly what you found out in your last post.
What I was asking is to run the the first instruction that is inside the get_uibutton function (pay attention at the code of my previous post) to understand if there are some toolbars to look into for your buttons.
If it returns None (and I suspect it will, but I’m still not that knowledgeable of pyrevit internals) that’s because pyrevit tabs are not yet ready during the startup.
Of course, when you reload the tabs/buttons are already there, so you can access them.
If my suppositions are right, this could be a good candidate for a github issue
just to clearify but i also tried your previous code and those also returned an empty list indeed.
Sorry from my end for not clearly stating this!
i’m talking about this code: print(ribbon.get_current_ui().get_pyrevit_tabs())
so indeed it can’t find nothing, but this even happens on doc.opening/ opend hooks as well.
Which is kind of strange since by then the tabs are defenitly already load in ( same for buttons).