top of page

Exporting Revit Element Parameters to Excel

In this blog post, I'll walk through a script that exports parameters of elements visible in the active Revit view to a CSV file. This tool helps users analyze and document Revit project data efficiently.


example of excel file that this python script produces

Overview

The script uses the Revit API to:

  1. Collect Elements: It gathers all elements visible in the current view.

  2. Extract Parameter Information: For each element, it retrieves the parameter name, parameter type (shared, built-in, or project parameters), the category that contains the parameter, and it also counts the amount of times that parameter occurs in the project.

  3. Export to CSV: lastly, the script prompts the user to select a save location and file name, then writes the gathered data into a CSV file.


Code Breakdown

  1. Initialize Revit Application and Document:

  • The script starts by accessing the active Revit document and view, initializing necessary components.

  1. Collect Elements and Parameters:

  • A FilteredElementCollector gathers elements from the active view. For each element, the script extracts parameters, storing details like name, type, and category and count.

  1. Export Revit Parameters to Excel via CSV File:

  • A SaveFileDialog lets the user specify where to save the output CSV. The script writes parameter data to the file, detailing each parameter's name, type, associated categories, and occurrence count.

  1. User Feedback:

  • Upon completion, a TaskDialog informs the user that the export was successful and provides the file location.


Benefits

This script automates data extraction, providing a structured and consistent way to document Revit element parameters. It's particularly useful for family management, project documentation, data analysis, and quality control, ensuring that project data is easily accessible and well-organized. This approach saves time and reduces manual errors in parameter documentation.


I made this script specifically to find out what parameters were being used in the projects in my firm.

  • If we have both project parameters and shared parameters with the same value, this will create errors in the schedule.

  • I also need to find out what parameters to add to my shared parameter library. If a project parameter is used 200 times, then it should probably be evaluated and potentially added to our shared parameter file.

  • If the spelling of a parameter is incorrect or abbreviated in a different way, I can also evaluate that with this CSV file as well.


Conclusion & Next Steps

Exporting Revit parameters to a CSV file allows for comprehensive project data management. By leveraging the Revit API, we can efficiently gather, analyze, and document critical project information. This script serves as a powerful tool for BIM managers and project coordinators, streamlining workflows and enhancing project documentation quality.


To improve upon this in the future, I'd like to make this into something similar to what DiRoots has available in their toolset. It allows you to control the parameters, modify them, or change them. It's a really powerful application that has great uses behind it if used effectively.


I actually created this because the DiRoots tool wasn't exporting my parameters for me and it was exporting everything in the project - not just what was in my active view. Maybe it'd be a good idea to include a user interface that allows the user to choose whether they want the whole project or just the active view.



What do you think could be added or modified to make this thing better? Leave your suggestions below



 

link to github

 
script.py
# Import necessary Revit API libraries
from Autodesk.Revit.DB import * 
from Autodesk.Revit.ApplicationServices import Application
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import ObjectType

# Import Python standard libraries
import csv
import os
import clr
import datetime
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import SaveFileDialog, DialogResult

UIAPP = __revit__.ActiveUIDocument #type: ignore
DOC = UIAPP.Document
ACTIVE_VIEW = UIAPP.ActiveView

# Define a function to check if a parameter is shared
def is_shared_parameter(param):
    return param.IsShared

def get_parameter_type(param):
    if param.IsShared:
        return "Shared Parameter"
    elif param.Definition.BuiltInParameter != BuiltInParameter.INVALID:
        return "Built-in Parameter"
    else:
        return "Project Parameter"

# Define the main function
def main():
    parameter_info = {} # Initialize a dictionary to store parameter information

    # Collect all elements in the document
    collector = FilteredElementCollector(DOC, ACTIVE_VIEW.Id)
    elements = collector.WhereElementIsNotElementType().ToElements()
    
    for elem in elements:
        category = elem.Category.Name if elem.Category else "No Category"
        param_set = elem.Parameters

        for param in param_set:
            param_name = param.Definition.Name
            param_type = get_parameter_type(param)
            param_key = (param_name, param_type)

            # Store parameter information in the dictionary
            if param_key not in parameter_info:
                parameter_info[param_key] = {
                    "Categories": set([category]),
                    "Count": 1
                }

            else:
                parameter_info[param_key]["Categories"].add(category)
                parameter_info[param_key]["Count"] += 1

    dialog = SaveFileDialog() 
    dialog.Filter = "CSV Files (*.csv)|*.csv"
    dialog.Title = "Save CSV File"
    dialog.FileName = "ParameterInfo"

    if dialog.ShowDialog() == DialogResult.OK: 
        output_file = dialog.FileName

        # Write the parameter information to a CSV file
        with open(output_file, mode='w', newline='') as file:
            writer = csv.writer(file) 
            writer.writerow(["Parameter Name", "Parameter Type", "Categories", "Count"]) 
            for (param_name, param_type), info in parameter_info.items():
                writer.writerow([param_name, param_type, "; ".join(info["Categories"]), info["Count"]]) 

        dialog = TaskDialog("Export Complete")
        dialog.MainInstruction = "CSV Export Successful"
        dialog.MainContent = f"{len(parameter_info)} parameters export to CSV file to:\n{output_file}"
        dialog.Show()
    else:
        TaskDialog.Show("Export Canceled", "The file save operation was canceled.")

# Call the main function
if __name__ == "__main__":
    main()

17 views0 comments

Comentarios


bottom of page