Filtered Element Collectors in Lib Folders? ( FilteredElementCollector )

Hello,
Is there any lost performance in a script if it’s calling FilteredElementCollector as a function from another .py file?
Is it significantly better to include the “collectors” within each script?

Thanks in advance!

IN GENERAL:
No there’s no significant performance loss when calling methods from a library.
The idea of libraries is there for code organisation & modularity.

TECHNICALLY:
yes there is an extra step of importing the library once.
We’re talking about fractions of fractions of seconds.
And it happens only once, after that the function is in memory and your computer won’t care where it came from.


But I wouldn’t stress it, using different .py files is incredibly usefull, it allows you to group methods that have a common context. As you say, it could be a good idea to create a whole lot of methods that collect data from the model from you.

You could do some methods like:
get_all_columns()
get_all_floors0
But the way you structure it is technically completely up to you.

I do suggest reading up on how python modules & imports work.

From what I can gather from your question you’re dipping your toes into your own imports.
So I have a tip for you that can save you a headache in the near future.

Pyrevit imports your non-script .py files once; and only once. It stores that import in a cache so that it can easily be reused.
Making changes to that .py file will NOT be seen by python in a subsequent script run, because pyrevit is looking at your cached .py and NOT the original.
You can force pyrevit to “reload” all imports on a script run by holding ctrl+alt+shift when clicking the button. This will clear the cache, and allow it to re-import the script.

The errors you’ll most likely see are:
Failed to import X from your_file.py , X does not exist.
Even when X is most definitly defined in “your_file.py”

2 Likes

Thank you @GertjanVDB … I appreciate your detailed response!
And I agree… it’s best to work smarter than harder and most importantly to keep the consistency in the scripts!

Thanks!