if i understand the question correctly , I reckon this is what you are looking for Bundle lib
put the repeating code in a different class in the lib folder and then you can call the methods easily as needed
try adding the path to lib in your script that will import the functions.
from sys import path
path.append(r'C:\path\to\lib')
can also use relative pathing
script_path = script.get_script_path()
common_root = os.path.dirname(os.path.dirname(os.path.dirname(script_path))) # this goes up the directory tree a couple levels
lib_path = os.path.join(common_root, 'lib', 'libfolder') # points to a subfolder in lib
sys.path.append(lib_path)
Don’t use from common.test import test
Try
from {library_file_name} import {function_name}
probably need to rename the function name to keep if from getting confusing, since you would be importing test from test.
I’ve also found that all changes to library files require reloading pyrevit. script.py files for the button scripts do not require a reload, just save the file, but lib require it.
Do you not need to add the library folder to path in each script to use? I havent been adding lib to my bundle.yaml so maybe this explains it… thought the bundle.yaml was just for the UI order
@Oded_F - what @sanzoghenzo showed is exactly how I would recommend - the lib folder lives in the main root extension folder
Also couldn’t agree more regarding pyrevit and chatgpt - it has very little knowledge of pyrevit as well as Revit API.
This is how I have my lib folder setup
Depends. Somebody very familiar with the Revit API and knows C# or python can quickly produce some pretty advanced scripts. You have to point it in the correct direction and explain exactly what you are looking for, but if you can’t identify issues just looking at the code in the browser, then you are going to waste a ton of time spinning in circles.
I found feeding it a script that is at least vaguely similar to what you are looking for and telling it what you want to modify it to do is better than asking it to create something from scratch. once you know how to ask it for what you want you can produce code absurdly quickly, but it’s a double edged sword if you treat it like your personal software developer.
YOU are the software developer. It’s just a text generator that produces code when you ask it the right way.
I ended up putting the lib under the extensions folder and worked for me! Also needed to restart revit, beyond reloading the Python setting, but can not reconstruct, so am not sure this is needed. Thank you all for your generous help!