7 Feb 2025
Export IFC from RVT using Design Automation API for Revit - Part I

A couple of years ago, we shared a way to export IFC from Revit models using Model Derivative API in this blog post. However, some limitations like the following, so Model Derivative API does not fit all our needs.
Known limitations of exporting IFC using Model Derivative API:
- Model Derivative API doesn't support custom IFC export settings set created by the recent Revit IFC Addin, which IFC exporter version is newer than v22.1.1.0. (Wishlist item: RVTLMV-3166)
- Model Derivative API doesn't support custom IFC property sets, requiring an extra user-defiled property set file. (Wishlist item: RVTLMV-3167)
- Model Derivative API doesn't support exporting IFC from a specific Revit view. Instead, it will export an IFC file from the whole model without the view-specific info. (Wishlist item: RVTLMV-3169)
- Model Derivative API doesn't always use the latest version of the Revit IFC addin synced with https://github.com/Autodesk/revit-ifc/releases.
Fortunately, we could work around the above limitations using Design Automation API for Revit to export IFC with Revit API. Before talking further, let's look at how to export IFC using Revit API. Here is the code example of the minimum, straightforward way:
using(var trans = new Transaction(doc, "Export IFC"))
{
trans.Start();
var exportPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var exportOptions = new IFCExportOptions();
exportOptions.FileVersion = IFCVersion.IFC4;
exportOptions.FilterViewId = view3DId;
exportOptions.AddOption("ExportRoomsInView", "true");
bool result = document.Export(exportPath, doc.Title, exportOptions);
trans.Rollback(); //!<<< Discard changes made during exporting IFC
}
The above code snippet looks easy, right? Afterward, we can use it in app bundle of Revit addin, then run it on Design Automation API for Revit to export IFC from Revit without installing/opening Revit Desktop.
Pre-configured IFC export setups on Design Automation API for Revit
What if we have created IFC export setups with custom configurations on Revit Desktop? How can we reuse that on Design Automation API for Revit? Do we need to call IFCExportOptions#AddOption for each custom setting we see on the dialogue of Revit Desktop, as shown below?
Well, unfortunately, the answer is yes ... we must call IFCExportOptions#AddOption for each setting on the below UI if we don't use default values, unfortunately.
But luckily, we can borrow some codes from the Revit IFC addin repository, the open source Revit IFC Addin project at https://github.com/Autodesk/revit-ifc, to achieve this. We will discuss how to do this later.
Some small things about the IFC export setups from Revit Desktop UI
First of all, the IFC export setups, including the built-in ones (e.g., <IFC2x3 Coordination View 2.0 Setup>) from the above Revit UI Dialog "Modify Setup" are created by the Revit IFC addin of https://github.com/Autodesk/revit-ifc.
- The built-in IFC export setups will be created when opening the Revit UI Dialog above.
- The custom configurations, the ones without "<>" like the "My IFC 2x3 CV2.0 setup" are serialized into JSON format by the IFC addin and be saved into Revit `.rvt` file using the Extensible Storage of Revit API, when a user creates one on the above Revit UI Dialog "Modify Setup", and the UI Dialog will parse custom JSON configurations from Revit `.rvt` file, when opening it.
- When clicking the "Export" button on the UI, it will convert the configurations into the options of IFCExportOptions by calling AddOption.
Export IFC with IFC export setups from Revit Desktop UI on Design Automation API for Revit
To make our app bundle to support reading IFC export setups created by the Revit IFC addin of https://github.com/Autodesk/revit-ifc, we can leverage codes of two utility classes (i.e. `IFCExportConfigurationsMap.cs` and `IFCExportConfiguration.cs`) under the path Source /IFCExporterUIOverride of Autodesk revit-ifc open source addin. While porting the codes from these two C# classes, we must remove the dependencies to UI-related codes.
Don't know what to do?
No problem, we've got you covered. Please check the readme and the code sample here:
- https://github.com/yiskang/aps-revit-ifc-exporter-appbundle?tab=readme-ov-file#description
- The ported codes can be found at https://github.com/yiskang/aps-revit-ifc-exporter-appbundle/tree/main/RevitIfcExporter/IFC
- The main implementation can be found at
- IFC/IFCExportConfiguration.cs - The data model represents a setup (a set of options) for an IFC expert task.
- IFC/IFCExportConfigurationsMap.cs - The map to store BuiltIn and Saved configurations for IFC export.
Once we ported the codes of `IFCExportConfigurationsMap.cs` and `IFCExportConfiguration.cs` to our own Revit Addin, then we can use them to add built-in IFC export setups and parse the custom saved setups on Revit Design Automation. (The full code sample can be found at RevitIfcExporter/MainApp.cs)
Here is the workflow:
- Firstly, we construct built IFC export setups and parse custom JSON-based setups saved in RVT file using IFCExportConfigurationsMap:
var configurationsMap = new IFCExportConfigurationsMap();
configurationsMap.AddBuiltInConfigurations(); //!<<< To construct map for built-in IFC export setups.
configurationsMap.AddSavedConfigurations(doc); //!<<< Parse the custom JSON-based IFC export setups saved in RVT file.
- Secondly, we choose which IFC export we want to use:
var exportConfig = configurationsMap["My IFC 2x3 CV 2.0 Setup"]; //!<<< Use custom one
// var exportConfig = configurationsMap["IFC 2x3 Coordination View 2.0"]; //!<<< Use built-in IFC 2x3 Coordination View 2.0 i.e. <IFC 2x3 Coordination View 2.0 setup>
// Make export visible elements in specified 3D view
exportConfig.VisibleElementsOfCurrentView = true;
ElementId filterViewId = this.GetFilterViewId(doc, inputParams); //!<<< Find view element id from given viewId in inputParams
if (filterViewId == ElementId.InvalidElementId)
{
exportConfig.UseActiveViewGeometry = false;
exportConfig.VisibleElementsOfCurrentView = false;
LogTrace($"!!!Warning!!!- No view found with the specified `viewId`: `{inputParams.ViewId}`, so the view-related settings would not take effect, e.g.`IFCExportConfiguration.VisibleElementsOfCurrentView` or `IFCExportConfiguration.UseActiveViewGeometry`.");
}
if (exportConfig.UseActiveViewGeometry)
{
exportConfig.ActiveViewId = filterViewId;
}
// Revit IFC addin uses absolute paths for UserDefinedPropertySets and UserDefinedParameterMappingFile, so change the paths to relative ones.
this.FixDependeciesPath(exportConfig);
- Then, convert the chosen export setup to the options of IFCExportOptions:
var exportOptions = new IFCExportOptions();
exportConfig.UpdateOptions(doc, exportOptions, filterViewId);
- Finally, call Revit Export API to convert RVT to IFC
using (var trans = new Transaction(doc, "Export IFC"))
{
try
{
trans.Start();
LogTrace("- Setting SetFailureHandlingOptions: SetClearAfterRollback=false...");
FailureHandlingOptions failureOptions = trans.GetFailureHandlingOptions();
failureOptions.SetClearAfterRollback(false);
trans.SetFailureHandlingOptions(failureOptions);
LogTrace("-- DONE... ");
LogTrace("- Execting the export task...");
result = doc.Export(exportPath, doc.Title, exportOptions);
if (!result)
throw new InvalidOperationException("Failed to export IFC");
LogTrace("-- DONE... ");
}
catch (Exception ex)
{
LogTrace("- Receieve exception, will print it out after rolling changes back...");
throw ex;
}
finally
{
//// Roll back the transaction started earlier, unless certain options are set.
if (result && (use2009BuildingStoreyGUIDs || exportConfig.StoreIFCGUID))
{
LogTrace("- Saving the changes made during exporting IFC...");
trans.Commit();
}
else
{
LogTrace("- Rolling back the changes made during exporting IFC...");
trans.RollBack(); //!<<< Dsicard changes in IFC export settings. This won't affect the exporting.
}
LogTrace("-- DONE... ");
}
}
How to find out why the IFC export fails or why the exported result is incorrect
To investigate the possible root cause, we can first check the Revit Journal File of the Revit Design Automation WorkItem by specifying the debug option like the following:
{
"activityId": "MyDaAppAlias.MyActivity+MyActivityAlias",
"arguments": {
// ....
"adskDebug": {
"uploadJobFolder": true
}
}
}
Once download the debugInfo.zip, we can find the Revit Journal File under "LocalAppDataADSKRX/Revit Interoperability {version}/Journals/"
That's all. Hope you enjoy it!
The full code sample of the above can be found at https://github.com/yiskang/aps-revit-ifc-exporter-appbundle
If you have questions about IFC export using Design Automation API for Revit, please contact APS support.