What do you do when you need to export multiple schedules as CSV from Revit?

What do you do when you need to export multiple schedules as CSV from Revit?
Today, we faced the task of exporting more than 30 Revit schedules to CSV.
By default, Revit 2023 only allows you to export schedules one by one, and there’s no built-in option to export several at once. Since we know this will become a recurring task, I volunteered to handle it myself.
And of course, I didn’t do it manually 😉. Instead, I wrote a short macro. Over the past months, my programming skills have improved to the point where I can confidently rely on AI for assistance—I’m much better at spotting mistakes in code, and my understanding of the code is also much deeper.
I let AI generate the initial code. It made five small mistakes, which I quickly corrected. Overall, the code was a good starting point: it didn’t work out of the box, but it looked solid and gave me a clear direction.
What the macro does (brief explanation)
Below the short explanation and the code ready to be used
- Standard boilerplate for
DocumentandUIDocument– your starting point for any Revit macro. - Getting user selection and checking against an empty ID. It’s not perfect, but this is a Revit macro where I assume users know what they’re doing… At least they need to be able to select some schedules before running it.
- Defining the path for exported schedules (I used the desktop). Feel free to change it. Personally, I treat my desktop as a workspace, so I’m fine with files landing there.
- Simple loop through the selection.
- Check if the ID references a schedule.
- Revit API class for export settings. If you’re curious, read more about CSV and Revit schedule export options.
- Delimiter choice: I used
^after giving it some thought—it’s a character I don’t expect to see in my schedules. Swap it to a comma if you don’t expect commas in your schedules. - ExportTextQualifier Enumeration: Google this if you want to understand what’s happening here.
- Done.
Example Macro Code
public void ExportSchedulesToCSV()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
if (selectedIds.Count == 0)
{
TaskDialog.Show("Error", "Please select at least one schedule view.");
return;
}
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
foreach (ElementId id in selectedIds)
{
ViewSchedule schedule = doc.GetElement(id) as ViewSchedule;
if (schedule == null) continue;
string fileName = Path.Combine(desktopPath, schedule.Name + ".csv");
ViewScheduleExportOptions options = new ViewScheduleExportOptions();
options.FieldDelimiter = "^"; // Change to comma if needed
options.TextQualifier = ExportTextQualifier.DoubleQuote;
schedule.Export(desktopPath, schedule.Name + ".csv", options);
}
TaskDialog.Show("Export Complete", "Schedules exported to Desktop.");
}