Get Revit Version while loading family

Sorry I tried same script in Revit 2022 and it detects Revit versions from older to current Revit version, but if I run the same script in Revit 2019 I get Revit version result until files in Revit 2020 but not later, it throws me an error that says:

The file is a newer format file where the structure of the BasicFileInfo storage has changed, or the file is saved in very old version of Revit without basic file data.

It looks this method does not know how to read that information in newer Revit files is my conclusion, but hopefully I am wrong.

First up, obligatory reminder that 2019 is not been supported for over 1.5 years and therefore is a security risk if kept in production. You’re so far outside the support window that I don’t have access to help troubleshoot.

Second up:

Can you screenshot the error? Note that when 2019 was being built no one would have been able to know what work had to happen 4 years later, which is why backwards compatibility isn’t possible, so while basic file info is intended to be as compatible as possible access issues are inevitable.

1 Like

I modified the script and made it like this, you can check output. the input is a directory path where is looking for all revit families in all subdirectories.

import clr
# Import Revit API and Services
clr.AddReference('RevitAPI')
clr.AddReference("RevitServices")
from Autodesk.Revit.DB import BasicFileInfo
from RevitServices.Persistence import DocumentManager
# Import System libraries
clr.AddReference('System')
from System import Enum
from System.IO import Directory, SearchOption, File, Path

# Define a function to get all .rfa files from a directory and its subdirectories
def get_rfa_files(directory):
    all_files = Directory.GetFiles(directory, '*.rfa', SearchOption.AllDirectories)
    return [f for f in all_files]

# The directory path from Dynamo
directory_from_path = IN[0]
# Get the list of .rfa files
paths = get_rfa_files(directory_from_path)
# Initialize lists for storing file info and errors
file_versions = []  # To store the actual Revit versions of the files
# Loop through each path to gather info
for path in paths:
    try:
        info = BasicFileInfo.Extract(path)
        version = int(info.Format)  # Extract the Revit version and convert to int
        file_versions.append(version)
    except Exception as e:
        error_message = str(e)
        file_versions.append(error_message)

OUT = paths,file_versions

Example of error:

I’m guessing this is where the code fails? Coding the ‘try / except’ is masking where the error is, limiting the report to ‘what’ the error is.

As I don’t have Revit 2019 or a mixed list of RFAs by directory I can’t reproduce, but I’d say the solution would be to run this in Dynamo for Revit 2024 instead of 2019.

1 Like

yeah we need to live with this, just run script in newer Revit version

1 Like