pyRevit icon indicating copy to clipboard operation
pyRevit copied to clipboard

pyRevit reload hook event

Open kirsch33 opened this issue 3 months ago • 3 comments

I have some code that I run in an app-init hook right now that works great. However it is rolled back in the event of a pyRevit reload.

I would like the ability to place a script somewhere that pyRevit executes near the end of its reload sequence to restore any needed code at this time.

I've seen some mention in places of a "startup.py" script that might serve this purpose but documentation is lacking and everything I've tried for this hasn't worked.

Note one thing: the code I need to run depends on the shared lib/ directory being available and added to sys.path, I suppose I could include it manually but that's not required anywhere else within the pyRevit ecosystem

Am I missing something or is this not easily possible right now ?

kirsch33 avatar Oct 01 '25 00:10 kirsch33

Hi @kirsch33, Indeed the startup script runs after the pyRevit reload. Can you explain how did you use it, and where did you place it, why isn't it doing the job ? Can you share some of you code or give more details about the "shared lib" dependency ? Thx

MohamedAsli avatar Oct 01 '25 07:10 MohamedAsli

Within my Tool.extension directory I have:

  • Tool.tab/
  • hooks/
  • lib/
  • extension.yaml

The code I tried calling from startup.py is within the lib/ folder which pyRevit usually handles adding to sys.path on its own. When I experimented with startup.py I seemed to have to do this manually but again I might be using it incorrectly

Specifically the code (although I know not officially supported) manually adds some coloring to the bottom title bar of the panels on my tools tab. This works great when called from app-init.py, it wasn't working at all from startup.py but again I couldn't find any really good info on where to put startup.py and if it needs to be in extension.yaml, etc

It might be as easy as pyRevit doesn't build the tabs/panels for an extension until after startup.py has ran in which case I'll have to figure out another method totally

kirsch33 avatar Oct 01 '25 12:10 kirsch33

For the startup you have to put it in the .extension directory, see here

Why are you coloring your title in the startup ? this is handled by the panel's bundle.yaml files, see here

Did I understand you well ?

MohamedAsli avatar Oct 01 '25 13:10 MohamedAsli