Making scripts "rocket-mode-save"

I’m trying to speed up my extension and thinking about setting it to rocket_mode_compatible.
Is this chatgpt answer correct, do i have to make sure to fix all my scripts to never have this on top? Or only for lib scripts as the “shared module” hint implies?

:warning: Caching ActiveView at import time

This is extremely common:

from pyrevit import revit
doc = revit.doc
view = doc.ActiveView

If that’s at the top of a shared module → Rocket Mode will bite you.


:white_check_mark: Best Practice Pattern for Rocket Mode

Instead of:

doc = revit.doc

Do this everywhere:

from pyrevit import revit

def get_doc():
    return revit.doc

Not sure what to reply…

Yes, you do not collect doc or views in modules, we do that sometimes and yes it may bite you.

Other that that… No

1 Like

Don’t forget you can do Ctrl + Alt + Shift + Click on your pyRevit button to force it to reload the libraries. Not good for production, but it has saved me in development many times.

I’m probably stuck in the past, but this snippet has always worked for me to avoid Rocket Mode issues:

from pyrevit import HOST_APP
uidoc = HOST_APP.uiapp.ActiveUIDocument
doc = uidoc.Document
1 Like

I want to move a bunch of my modeless windows to dockable panes - do i have to look out for anything in regards to rocket mode? If i want to clean the engine or anything crashes hard, just do the same keyboard shortcut to reopen it?