Call External pyRevit Command

Hi,

Is it possible to ‘Execute external commands’ on a custom extension command from within a script.py?

For instance looking at the journal file this is the record of the pyRevit Spy command:

Jrn.RibbonEvent “Execute external command:CustomCtrl_%CustomCtrl_%CustomCtrl_%pyRevit%pyRevit%Spy%List Elements:pyrevitcore-pyrevit-pyrevit-tools-spy-listelements”

Is it possible to call this from within another script?

Thanks,
Eoin

from pyrevit.loader import sessionmgr

# put the unique id of the command there
sessionmgr.execute_command("pyrevitdevtools-pyrevit-****")

To get the unique Id of any pyRevit tool, Shift+Win Click on the button and click on the appropriate item in the menu :slight_smile:

1 Like

Thanks, you’re a star Ehsan. This addin just gets better and better!

1 Like

Haha of course and thank you. Just out of curiousity what’s a use case for calling an external command directly?

1 Like

The use case here is in a doc-opened hook to call a loaded model audit script every time a model is opened. I didn’t want to copy / paste the code just because I couldn’t reference it!

1 Like

sounds like a preflight check ;p

Sort of yes. But specific to our office standards and unavoidable

1 Like

I like the ‘unavoidable’ !

2 Likes

@eirannejad thanks for the solution!
@eprunty can you please share how you used sessionmgr.execute_command with the doc-opened hook? I copied the code to the hooks/doc-opened.py file but an error occurred:

@eprunty Also out of curiosity, what kinds of checks are you doing in your audit?

Unfortunately I also ran into issues with this. It worked in the session I had open but then when I closed and opened a new Revit session it stopped working in doc-opened and I’ve had to remove the hook until such a time that I can look into it again. Perhaps @eirannejad can shed some light on sessionmgr’s availability in the doc-opened context?

@GertjanVDB it checks for elements of our office standard on model startup between elements and parameters applied