Export

Export

The Revit API allows for a Revit document, or a portion thereof, to be exported to various formats for use with other software. The Document class has an overloaded Export() method that will initiate an export of a document using the built-in exporter in Revit (when available). For more advanced needs, some types of exports can be customized with a Revit add-in, such as export to IFC and export to Navisworks. (Note, Navisworks export is only available as an add-in exporter).

The Document.Export() method overloads are outlined in the table below.

Table: Document.Export() Methods

Format

Export() parameters

Comments

gbXML

String, String, MassGBXMLExportOptions

Exports a gbXML file from a mass model document

gbXML String, String, GBXMLExportOptions Exports the document in Green-Building XML format. If EnergyDataSettings is set to use conceptual models, this function cannot be used: instead use the method above.

IFC

String, String, IFCExportOptions

Exports the document to the Industry Standard Classes (IFC) format.

NWC

String, String, NavisworksExportOptions

Exports a Revit project to the Navisworks .nwc format. Note that in order to use this function,you must have a compatible Navisworks exporter add-in registered with your session of Revit.

DWF

String, String, ViewSet, DWFExportOptions

Exports the current view or a selection of views in DWF format.
DWFX String, String, ViewSet, DWFXExportOptions Exports the current view or a selection of views in DWFX format.
FBX String, String, ViewSet, FBXExportOptions Exports the document in 3D-Studio Max (FBX) format.
DGN String, String, ICollection(ElementId), DGNExportOptions Exports a selection of views in DGN format.
DWG String, String, ICollection(ElementId), DWGExportOptions Exports a selection of views in DWG format.
DXF String, String, ICollection(ElementId), DXFExportOptions Exports a selection of views in DXF format.
SAT String, String, ICollection(ElementId), SATExportOptions Exports the current view or a selection of views in SAT format.
ADSK String, String, View3D, ViewPlan, BuildingSiteExportOptions Exports the document in Autodesk Civil3D® format.

Exporting to gbXML

There are two methods for exporting to the Green Building XML format. The one whose last parameter is MassGBXMLExportOptions is only available for projects containing one or more instances of Conceptual Mass families. The MassGBXMLExportOptions object to pass into this method can be constructed with just the ids of the mass zones to analyze in the exported gbXML, or with the mass zone ids and the ids of the masses to use as shading surfaces in the exported gbXML. Whe using masses, they must not have mass floors or mass zones so as not to end up with duplicate surface information in the gbXML output.

The GBXMLExportOptions object used for the other gbXML export option has no settings to specify. It uses all default settings. Note that this method does not generate the energy model. The main energy model must already be stored in the document before this export is invoked.

Exporting to IFC

Calling Document.Export() using the IFC option will either use the default Revit IFC export implementation or a custom IFC exporter, if one has been registered with the current session of Revit. In either case, the IFCExportOptions class is used to set export options such as whether to export IFC standard quantities currently supported by Revit or to allow division of multi-level walls and columns by levels.

Exporting to Navisworks

The Export method for Navisworks requires a compatible Navisworks exporter add-in registered with the current Revit session. If there is no compatible exporter registered, the method will throw an exception. Use the OptionalFunctionalityUtils.IsNavisworksExporterAvailable() method to determine if a Navisworks exporter is registered.

The NavisworksExportOptions object can be used to set numerous export settings for exporting to Navisworks, such as whether to divide the file into levels and whether or not to export room geometry. Additionally, the NavisworksExportOptions.ExportScope property specifieds the export scope. The default is Model. Other options include View and SelectedElements. When set to View, the NavisworksExportOptions . ViewId property should be set accordingly. This property is only used when the export scope is set to View. When set to SelectedElements, the NavisworksExportOptions . SetSelectedElementIds() method should be called with the ids of the elements to be exported.

Exporting to DWF and DWFX

Both DWF and DWFX files can be exported using the corresponding Document.Export() overloads. Both methods have a ViewSet parameter that represents the views to be exported. All the views in the ViewSet must be printable in order for the export to succeed. This can be checked using the View.CanBePrinted property of each view. The last parameter is either DWFExportOptions or DWFXExportOptions. DWFXExportOptions is derived from DWFExportOptions and has all the same export settings. Options include whether or not to export the crop box, the image quality whether or not to export textures to 3D DWF files, and the paper format.

Code Region: Export DWF

public bool ExportViewToDWF(Document document, View view, string pathname)
{
    DWFExportOptions dwfOptions = new DWFExportOptions();
    // export with crop box and area and room geometry
    dwfOptions.CropBoxVisible = true;
    dwfOptions.ExportingAreas = true;
    dwfOptions.ExportTexture = false;
    ViewSet views = new ViewSet();
    views.Insert(view);
    return (document.Export(Path.GetDirectoryName(pathname),
        Path.GetFileNameWithoutExtension(pathname), views, dwfOptions));
}

Exporting to 3D-Studio Max

FBX Export requires the presence of certain modules that are optional and may not be part of the installed Revit, so the OptionalFunctionalityUtils . IsFBXExportAvailable() method reports whether the FBX Export functionality is available. The Export() method for exporting to 3D-Studio Max has a ViewSet parameter representing the set of views to export. Only 3D views are allowed. The FBXExportOptions parameter can be used to specify whether to export without boundary edges, wther to use levels of detail, and whether the export process should stop when a view fails to export.

Exporting to CAD Formats

Exporting to DGN , DWG and DXF format files have similar export methods and options.

DGN , DWG and DXF Export all require the presence of certain modules that are optional and may not be part of the installed version of Revit, so the OptionalFunctionalityUtils class as corresponding methods to reports whether the each of these types of export functionality are available.

The Export() methods for exporting to DGN, DWG and DXF formats all have a parameter representing the views to be exported (as an ICollection of the ElementIds of the views). At least one valid view must be present and it must be printable for the export to succeed. This can be checked using the View.CanBePrinted property of each view.

The export options for each of these formats derives from BaseExportOptions, so there are many export settings in common, such as the color mode or whether or not to hide the scope box. BaseExportOptions also has a static method called GetPredefinedSetupNames() which will return any predefined setups for a document. The name of a predefined setup can then be passed into the static method GetPredefinedOptions() available from the corresponding options class: DWGExportOptions, DGNExportOptions or DXFExportOptions. The export options for DWG and DXF files have even more options in common as they share the base class ACADExportOptions.

The following example exports the active view (if it can be printed) to a DGN file using the first predefined setup name and the predefined options, without making any changes.

Code Region: Export DGN

public bool ExportDGN(Document document, View view)
{
    bool exported = false;
    // Get predefined setups and export the first one
    IList<string> setupNames = BaseExportOptions.GetPredefinedSetupNames(document);
    if (setupNames.Count > 0)
    {
        // Get predefined options for first predefined setup
        DGNExportOptions dgnOptions = DGNExportOptions.GetPredefinedOptions(document, setupNames[0]);

        // export the active view if it is printable
        if (document.ActiveView.CanBePrinted == true)
        {
            ICollection<ElementId> views = new List<ElementId>();
            views.Add(view.Id);
            exported = document.Export(Path.GetDirectoryName(document.PathName),
                Path.GetFileNameWithoutExtension(document.PathName), views, dgnOptions);
        }
 }
           
    return exported;
}

For these file types it is possible to specify or modify various mapping settings, such as layer mapping or text font mapping by creating the corresponding table and passing it into the appropriate method of the BaseExportOptions class. For layer mapping, you may alternatively pass in a string value to BaseExportOptions.LayerMapping of a predefined layer mapping style or the filename of a layer mapping file. For more information on creating or modifying export tables, see the Export Tables topic.

Exporting to SAT

The Export method for SAT has a parameter representing the views to be exported (as an ICollection of the ElementIds of the views). At least one valid view must be present and it must be printable for the export to succeed. This can be checked using the View.CanBePrinted property of each view. The SATExportOptions object has no settings to specify. It uses all default settings.

Exporting to Civil Engineering Design Applications

The last Export() method exports a 3D view of the document in the format of Civil Engineering design applications. One parameter of the method is a Viewplan that specifies the gross area plan. All the areas on the view plan will be exported and it must be 'Gross Building' area plan. To check whether its area scheme is Gross Building, use the AreaScheme.GrossBuildingArea property. The BuildingSiteExportOptions object allows custom values for settings such as gross area or total occupancy.