Could be helpful to have a way to run selected scripts on startup of revit to do administrative things, register events, etc
Could be added as an option in settings similar to rps, or perhaps event easier, have a startup folder in which all scripts get executed at after loading.
See Advanced Bundles section here: http://eirannejad.github.io/pyRevit/howtoaddscriptsandtabs/#extension-bundle-structure
Create a .smartbutton bundle and define __selfinit__ and do whatever is necessary on startup. pyRevit runs this method at startup on any .smartbutton
See Sync Views tool as example.
But I understand the simplicity of a startup script folder and will add that to pyRevit as well. Keep this issue open.
Resolved.
UI Extensions can now have a script in root folder that will be executed on every pyRevit load. This script can be used to make necessary adjustments to the environment as needed by the UI extension.
The script filename must end in startup.py
pyRevit runs the startup script in a dedicated IronPython engine and output window. Thus the startup script is isolated and can not hurt the load process.
All errors will be printed to the dedicated output window similar to the way errors are printed from pyRevit commands.
See extensions/pyRevitCore/startup_script_test.py
Will be published in 4.4 soon
It seems like the feature is broken in 4.5.
If you run Revit with startup.py in any extension, it'll show a messagebox with error and pyRevit won't run.
In case if you first run pyRevit and after that added a startup.py, when you click Reload you will receive this error message:
IronPython Traceback:
Traceback (most recent call last):
File "C:\Users\Aleksey.Melnikov\AppData\Roaming\pyRevit\pyRevit-v45rc\pyRevit\extensions\pyRevitCore.extension\pyRevit.tab\pyRevit.panel\tools.stack3\Reload.pushbutton\script.py", line 18, in
File "C:\Users\Aleksey.Melnikov\AppData\Roaming\pyRevit\pyRevit-v45rc\pyRevit\pyrevitlib\pyrevit\loader\sessionmgr.py", line 182, in load_session
File "C:\Users\Aleksey.Melnikov\AppData\Roaming\pyRevit\pyRevit-v45rc\pyRevit\pyrevitlib\pyrevit\loader\sessionmgr.py", line 136, in _new_session
File "C:\Users\Aleksey.Melnikov\AppData\Roaming\pyRevit\pyRevit-v45rc\pyRevit\pyrevitlib\pyrevit\loader\sessionmgr.py", line 434, in execute_script
TypeError: ScriptExecutor() takes no arguments (1 given)
Script Executor Traceback:
Microsoft.Scripting.ArgumentTypeException: ScriptExecutor() takes no arguments (1 given)
...
I couldn't understand what exactly was changed. Fixing sessionmgr.py script didn't help me with it.
But I hope it will be easy to fix. Thank you!
Fixed sorry for the inconvenience
Is there a similar way of initiating a script when a document loads?
Not at the moment
@thazell in the startup.py you could register for an event handler that listens to "DocumentOpened" http://www.revitapidocs.com/2018.1/7e5bc7a1-0475-b2ec-0aec-c410015737fe.htm and performs actions based on file name, workshare status, etc. like "warning you are in central model" or "running low on disk space - risking a corrupt sync". I use it here for example: https://github.com/hdm-dt-fb/rvt_fixme
Thanks @hdm-dt-fb
Most helpful comment
@thazell in the startup.py you could register for an event handler that listens to "DocumentOpened" http://www.revitapidocs.com/2018.1/7e5bc7a1-0475-b2ec-0aec-c410015737fe.htm and performs actions based on file name, workshare status, etc. like "warning you are in central model" or "running low on disk space - risking a corrupt sync". I use it here for example: https://github.com/hdm-dt-fb/rvt_fixme