Project/Workflow Name:
Automated Sheet Creation from CSV in Revit
Objective:
To automate the process of creating over 500 sheets in Revit from a CSV file, significantly reducing manual input time and effort.
Tools & Features Used:
- Maestro script generation
Workflow Overview:
The goal was to generate Revit sheets using a CSV file containing sheet numbers and names. The first row of the CSV was skipped, while Columns A and B were used to reference the sheet number and sheet name, respectively. The CSV was located in a specific folder on the desktop. Using Maestro’s AI Generation tool, I provided a prompt describing the task and received a script that could be run within the Maestro UI.
Prompt:
I need a script to take the rows of a CSV and create sheets within the Revit project. The first row should be skipped and only Columns A and B should be referenced. Column A has the sheet number and column B is the sheet name. The CSV can be located in a folder on the desktop called Sheet Creation Sample in the SheetIndexSample.csv.
Generated Code:
import clr
import csv
import os
from System import Guid
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, ViewSheet, Transaction
# Function to get the desktop path
def get_desktop_path():
return os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
# Function to read the CSV file and return the data, skipping the first row
def read_csv_data(csv_path):
with open(csv_path, 'r') as file:
reader = csv.reader(file)
next(reader) # Skip the first row (header)
return [row for row in reader]
# Function to check if a sheet with the given number already exists
def sheet_number_exists(doc, sheet_number):
sheets = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets).WhereElementIsNotElementType().ToElements()
return any(sheet.SheetNumber == sheet_number for sheet in sheets)
# Function to create a new sheet
def create_sheet(doc, sheet_number, sheet_name):
new_sheet = ViewSheet.Create(doc, ElementId.InvalidElementId)
new_sheet.SheetNumber = sheet_number
new_sheet.Name = sheet_name
return new_sheet
# Main execution
try:
# Define the path to the CSV file
desktop_path = get_desktop_path()
csv_path = os.path.join(desktop_path, 'Sheet Creation Sample', 'SheetIndexSample.csv')
# Read the data from the CSV file
sheet_data = read_csv_data(csv_path)
# Start a new transaction to create sheets
t = Transaction(doc, "Create Sheets from CSV")
t.Start()
for row in sheet_data:
if len(row) < 2:
continue # Skip rows that don't have at least 2 columns
sheet_number = row[0]
sheet_name = row[1]
# Only create the sheet if a sheet with the same number doesn't exist
if not sheet_number_exists(doc, sheet_number):
create_sheet(doc, sheet_number, sheet_name)
# Commit the transaction
t.Commit()
except Exception as e:
# If there's an error, throw it again after catching
raise e
Results:
The solution was implemented successfully, creating a custom script and over 500 sheets in Revit in less than five minutes. The workflow was simplified and completed using Maestro’s generated script after only two attempts.
Challenges & Insights:
Initially, the first generated script required some adjustments to correctly reference the CSV columns and structure. However, after refining the prompt, the second attempt produced a fully functional solution in minutes, which highlighted how quickly and effectively Maestro can assist with tedious and repetitive tasks. This approach significantly reduced the time spent on manual sheet creation from hours to just minutes.