Scriptception - Run one script from within another

Hello to the PyRevit community :cowboy_hat_face:

For Dynamo usage within my company, I have a custom node consisting of Python that logs user info.

I have recently deployed a couple of custom Python tools that I have embedded into my company’s deployment for PyRevit that I was hoping to also track usage of.

To do so I was hoping to be able to ‘import’ my usage tracking python script into my ‘script’ file for each PyRevit custom tool so I can avoid copying a big chunk of usage tracking code every time.

Do you know if it is possible using the following sort of method?

I tried saving the usage tracking script at the root directory of the custom button and called it ‘file.py’ as below:
image

I then included the line import file at the beginning of my script but it falls over as it says it cannot find the import of ‘file’.

Any help appreciated!

hi @haganjake2
I guess this is what you are looking for Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.

create a lib with your custom module at the extension level in a lib folder and use the defs from your lib:
you should be able to do something like that afterwards.

Watch out! New lib methods, you might have to reload pyRevit first.

from mylib import tracking_method

pyRevit has some logging capabilities, you might want to explore that first.

https://pyrevit.readthedocs.io/en/latest/pyrevit/coreutils/logger.html

or the telemetry system

Ehsan did a video about telemetry system and logging too on YT

1 Like

Hi @Jean-Marc,

Thanks for both of your suggestions - The reason I wish to proceed with the current tracking is that it is already preformatted and linked to our own internal PowerBI dashboards.

When trying to add the ‘lib’ folder am I correct in placing it in this location?
image

As currently when trying to run the script (after reloading) that includes the from lib import file line I get the runtime error of “ImportError: No module named lib”

Whilst this page was useful in my understanding of the concept, it wasn’t specific about the location and application of where to place the lib directory!

Thanks in advance

Nah, i think the location can vary (button, tab folder,…) But you need to name your lib. See examples in Pyrevit tools folders and in the pychilizer extension.

1 Like