DEV Community

Cover image for A Gathering of revit files
Symon  Kipkemei
Symon Kipkemei

Posted on

A Gathering of revit files

Problem

I wanted to update my Revit template based on all the Revit projects I have done previously in the past.

The challenge I encountered was that the Revit files were scattered in several folders of sub folders of subfolders. Retrieving them would be a lot harder and a tedious work.

Besides that, Some Revit files are back-up files that are currently consuming unnecessary storage space. Filtering through to get the latest native Revit files would be a lot harder.

Below is a script that I developed that would assist gather all Revit files in a project directory

Scripting process

Import pathlib module

import pathlib
Enter fullscreen mode Exit fullscreen mode

Establish the project directory. In this case a project directory is the root folder for all your architectural projects

# path to my desktop
start_path = "/mnt/d/New folder"
start_path_obj = pathlib.Path(start_path)
Enter fullscreen mode Exit fullscreen mode

Create a new directory where you would like to store your revit files

# create new folder
new_path = pathlib.Path(f"{start_path}/Revit-bastards")
new_path.mkdir(exist_ok=True )
Enter fullscreen mode Exit fullscreen mode

Defining a function that would establish if a file is a revit file, if it is a revit file will be moved to a new directory/ folder specified above

def check_move_files(path,new_path) -> None:
    """check if file is  png it then moves to a separate folder

    Args:
        path (Path): path of the current folder/file/directory

    """

    if path.suffix == ".rvt" or path.suffix == ".txt":
        # create a new path for the level_1 
       new_filepath = new_path.joinpath(path.name)

       #move files
       path.replace(new_filepath)

Enter fullscreen mode Exit fullscreen mode

We can start scanning across for the revit files,incase we encounter a folder, we will open the folder and check for the revit files level 1....level 2....level 3

We can scan for files until the script is done.

# starting level
for level_1 in start_path_obj.iterdir():
    if level_1.is_file():
        check_move_files(level_1,new_path)

    # level 1
    else:
        level_1_path = start_path_obj.joinpath(level_1)
        for level_2 in level_1_path.iterdir():
            if level_2.is_file():
                check_move_files(level_2,new_path)
            #level 2
            else:
                level_2_path = level_1_path.joinpath(level_2)
                for level_3 in level_2_path.iterdir():
                    if level_2.is_file():
                        check_move_files(level_3,new_path)
Enter fullscreen mode Exit fullscreen mode

To check the full script, checkout :
https://github.com/symonkipkemei/mover

if you encounter any challenges, feel free to leave an issue:
https://github.com/symonkipkemei/mover/issues

Thank you!!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up