IFC Export Options

IFC Export Options

Anonymous
Not applicable
13,242 Views
18 Replies
Message 1 of 19

IFC Export Options

Anonymous
Not applicable

Hey,

 

i need to write an IFC exporter, but I can't find any Class in the API for all export settings. I mean, yes the is the "IFCExportOptions" Class, but it just has like 6 Settings instead of more than 20 in the Revit software UI as seen in the picture. Especially the blue marked settings are really important in my case.

Accepted solutions (1)
13,243 Views
18 Replies
Replies (18)
Message 2 of 19

jeremytammik
Autodesk
Autodesk

If you wish to dive deeper into the IFC export, you should take a look at the Revit IFC Export open source project:

 

https://sourceforge.net/p/ifcexporter/discussion/general

 

https://github.com/Autodesk/revit-ifc

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 19

Anonymous
Not applicable
Accepted solution

@Anonymous @jeremytammik

The IFCExportOptions relies on the IFCExportConfiguration class which unfortunately is not described in the Revit API.

 

First we define our document and we create an instance of the IFCExportOptions class.

 

 

 

 

 

Document doc;
IFCExportOptions IFCExportOptions = new IFCExportOptions();

 

 

 

 

 

 

Then, import the reference of the IFCExportUI. This is located at the

"C:\Program Files\Autodesk\Revit 2020\AddIns\IFCExporterUI\IFCExportUI.dll"

 

You can now configure the extended IFC Options which are not described in the Revit API but are described in the IFC Export Revit addin using the IFCExportConfiguration class.IFC Export Configurations.jpg

 

First create an instance of the IFC Export Configuration Class. 

 

 

 

 

 

 

BIM.IFC.Export.UI.IFCExportConfiguration myIFCExportConfiguration = BIM.IFC.Export.UI.IFCExportConfiguration.CreateDefaultConfiguration();

 

 

 

 

 

 

 

Then add the required settings in this IFCExportConfiguration. Here I added only the "Export only element visible in view" setting shown at the image below.

 

Export only element in view.jpg

 

 

 

 

 

 

myIFCExportConfiguration.VisibleElementsOfCurrentView = true;

 

 

 

 

 

 

We can also apply any other setting that exist in the IFCExportConfiguration class and which are equivalent to the IFC Export User Interface.

IFCExportConfigurationParameters.jpg

 

Then, we need to pass the options from the IFCExportConfiguration to the IFCExportOptions. Here we need to define a ElementId which refers to a 3D view. however, this is only used is the IFCExportConfiguration.visibleElementsOfCurrentView is set to true. If we don't want to define a 3D view we can also set this to null. 

 

 

 

 

 

ElementId ExportViewId = null;
myIFCExportConfiguration.UpdateOptions(IFCExportOptions, ExportViewId);

 

 

 

 

 

 

Last but not least we define the Directory for the export and we process the export procedure.

 

 

 

 

 

string Directory = @"c:\"
doc.Export(Directory, doc, IFCExportOptions);

 

 

 

 

 

 

Below the whole code alltogether.

 

 

 

 

 

//Define Document
Document doc;

//Create an Instance of the IFC Export Class
IFCExportOptions IFCExportOptions = new IFCExportOptions();

//Apply the IFC Export Setting (Those are equivalent to the Export Setting in the IFC Export User Interface)
myIFCExportConfiguration.VisibleElementsOfCurrentView = true;

//Create an instance of the IFC Export Configuration Class
BIM.IFC.Export.UI.IFCExportConfiguration myIFCExportConfiguration = BIM.IFC.Export.UI.IFCExportConfiguration.CreateDefaultConfiguration();

//Define the of a 3d view to export
ElementId ExportViewId = null;

//Pass the setting of the myIFCExportConfiguration to the IFCExportOptions
myIFCExportConfiguration.UpdateOptions(IFCExportOptions, ExportViewId);

//Define the output Directory for the IFC Export
string Directory = @"c:\"

//Process the IFC Export
doc.Export(Directory, doc, IFCExportOptions);

 

 

 

 

 

 

I hope the above are useful. Let me know if anyone has any comment.

 

Best,

Alex

Message 4 of 19

Anonymous
Not applicable

This is awesome 🙂

 

Thanks, you saved me a lot of time, because i was about to manipulate the IfcExporter, which i found in my case is not a good solution.

0 Likes
Message 5 of 19

juan_hoyos4
Observer
Observer

Is there an option to export to ifczip?

0 Likes
Message 6 of 19

jeremy_tammik
Alumni
Alumni

Please read the IFCExportOptions documentation to answer your question:

 

https://www.revitapidocs.com/2021.1/b90adabd-0502-fb8f-3a0d-bfa412393f61.htm

 

As far as I can tell, this functionality is not provided built-in.

 

You could implement functionality to capture any output file generated by Revit and zip it, if that fulfils your purpose.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 7 of 19

strsuraj
Enthusiast
Enthusiast

Inorder to get access to IFC File type, you have to add one more DLL RevitAPIIFC.dll and this will give access to all IFC file formats. 

myIFCExportConfiguration.IFCFileType = Autodesk.Revit.DB.IFC.IFCFileFormat.IfcZIP; // it has other options as well

 

this worked for me. 

 

Thanks,

Suraj

0 Likes
Message 8 of 19

H.echeva
Advocate
Advocate

Alex,

That is amazing.

Thank you very much!

What about setting the File Header Information, Project Adress and Classification settings?

Any chance to define those as well?

I see that in the same dll there's another namespace called BIM.IFC.Export.UI.Properties that contain properties with these names. Can I link these somehow to the IFCExportConfiguration?

Kind regards

0 Likes
Message 9 of 19

H.echeva
Advocate
Advocate

Also, I don't see a way to set up the coordinates?

0 Likes
Message 10 of 19

fritz.sandner
Community Visitor
Community Visitor
Hi Josef,
I'm using 'Autodesk.IFC.Export.UI.dll' from Revit2022 Installation and it's working quite good.
But a different customer is using Revit 2021 and he get strange exception with missing Method
'BIM.IFC.Export.UI.IFCExportConfiguration.set_ActivePhaseId(Int32)'

how can i establish Addon which is working for different Revit versions?

thanks Fritz
0 Likes
Message 11 of 19

jeremy_tammik
Alumni
Alumni
Message 12 of 19

jacopo_chiappetti
Enthusiast
Enthusiast

Thanks, you saved my day.

if I could add something to help identify the right properties, just create your config in revit then export it in json: properties names are just stored in the file with right values

 

{
  "Name": "<Configurazione durante la sessione>",
  "IFCVersion": 21,
  "IFCFileType": 0,
  "SpaceBoundaries": 0,
  "SitePlacement": 0,
  "ActivePhaseId": {
    "IntegerValue": 0
  },
  "ExportBaseQuantities": false,
  "SplitWallsAndColumns": false,
  "ExportInternalRevitPropertySets": true,
  "ExportIFCCommonPropertySets": true,
  "Export2DElements": true,
  "VisibleElementsOfCurrentView": true,
  "Use2DRoomBoundaryForVolume": false,
  "UseFamilyAndTypeNameForReference": false,
  "ExportPartsAsBuildingElements": false,
  "ExportSolidModelRep": false,
  "ExportSchedulesAsPsets": false,
  "ExportUserDefinedPsets": false,
  "ExportUserDefinedPsetsFileName": "C:\\Program Files\\Autodesk\\Revit 2020\\AddIns\\IFCExporterUI\\DefaultUserDefinedParameterSets.txt",
  "ExportUserDefinedParameterMapping": false,
  "ExportUserDefinedParameterMappingFileName": "",
  "ExportBoundingBox": false,
  "IncludeSiteElevation": false,
  "UseActiveViewGeometry": false,
  "ExportSpecificSchedules": false,
  "TessellationLevelOfDetail": 0.75,
  "UseOnlyTriangulation": false,
  "StoreIFCGUID": true,
  "ExportRoomsInView": false,
  "ExportLinkedFiles": false,
  "ActiveViewId": 0,
  "ExcludeFilter": "",
  "COBieCompanyInfo": "",
  "COBieProjectInfo": "",
  "IncludeSteelElements": true,
  "IsBuiltIn": false,
  "IsInSession": true,
  "FileVersionDescription": "IFC 2x3 Coordination View 2.0"
}

 

 

Message 13 of 19

victor.bastidas
Enthusiast
Enthusiast

Hi Alex! 

Thanks for this example. 

 

@jacopo_chiappetti and Alex, 

 

I haven't been able to find much documentation on using those JSON exports. I'm using IronPython on RevitPythonShell, Revit 2022. I'll share how I'm trying to import this JSON file. It apparently runs, but whenever I try to use the UpdateOptions method it gives a null exception.

 

import clr
import json
clr.AddReferenceToFileAndPath(r'C:\Program Files\Autodesk\Revit 2022\AddIns\IFCExporterUI\Autodesk.IFC.Export.UI.dll')
import BIM
clr.AddReference('System.Web.Extensions')
from System.Web.Script.Serialization import JavaScriptSerializer
from System.Collections.Generic import Dictionary,IDictionary
from System import DateTime

with open(r'C:\Users\myuser\Downloads\IFCConfiguration.json','r') as f:
	config=json.load(f)
	
myIfcOptions = IFCExportOptions()

myIFCExportConfiguration=BIM.IFC.Export.UI.IFCExportConfiguration()
myIFCExportConfiguration=BIM.IFC.Export.UI.IFCExportConfiguration.CreateDefaultConfiguration()

myIFCExportConfiguration.VisibleElementsOfCurrentView = True

datefromjson=config['ClassificationSettings']['ClassificationEditionDate']
datefromjson.Trim('/')
millisec=int(datefromjson.split('(')[1].split(')')[0])
config['ClassificationSettings']['ClassificationEditionDate']=DateTime(1970,1,1).AddMilliseconds(millisec)

config['ClassificationSettings']=Dictionary[str,object](config['ClassificationSettings'])
config['ProjectAddress']=Dictionary[str,object](config['ProjectAddress'])
config=Dictionary[str,object](config)

serializer = JavaScriptSerializer()
print('Antes:',myIFCExportConfiguration)

myIFCExportConfiguration.DeserializeFromJson(config,serializer)


print('Despues:',myIFCExportConfiguration)

collector = FilteredElementCollector(doc)
views = collector.OfCategory(BuiltInCategory.OST_Views).ToElements()
view = next((v for v in views if v.Name == 'EXPORT - NAVIS'), None)

ExportViewId = view.Id

myIFCExportConfiguration.UpdateOptions(myIfcOptions, ExportViewId)

tr=Transaction(doc,'IFC Export')
tr.Start()
doc.Export("C:/Users/myuser/Downloads",doc.PathName.Split('/')[-1]+'.ifc',myIfcOptions)
tr.Commit()

 

As it can be seen, I tried cleaning the config json a little bit, but when exploring the properties on the object with the ones on the JSON file, the object is missing ExportMaterialPsets and SelectedSite.

 

I haven't really been able to export with this JSON. 

 

Is there any way to see all saved configurations and simply select one? I could use that way since we have that IFC Export configuration saved on all our RVT C4R models. 

 

Thanks again for your insights!

 

Víctor

Message 14 of 19

victor.bastidas
Enthusiast
Enthusiast

Just if anyone eeeeever gets to this point of fighting agains the null pointer exception... 

 

It gets created by this line: 

https://github.com/Autodesk/revit-ifc/blob/master/Source/IFCExporterUIOverride/IFCExportConfiguratio... 

 

So, whenever this runs: 

 

 

case "ActivePhaseId":
if (IFCPhaseAttributes.Validate(ActivePhaseId))
options.AddOption(prop.Name, ActivePhaseId.ToString());

 

 

The Validate Method in here: 

 

 

      static public bool Validate(int phaseId)
      {
         ElementId checkPhaseId = new ElementId(phaseId);
         if (checkPhaseId == ElementId.InvalidElementId)
            return false;

         Element checkPhase = IFCCommandOverrideApplication.TheDocument.GetElement(checkPhaseId);
         return (checkPhase != null && (checkPhase is Phase));
      }

 

 

Fails, because accessing IFCCommandOverrideApplication.TheDocument gives a None value. 

 

It can be assigned to the current doc first, but apparently this method has to be used first: 

 

public void OnIFCExport(object sender, CommandEventArgs args)

 

Which is under class IFCCommandOverrideApplication.

 

If you've followed up until here, you probably know what you're doing. 

 

Else, feel free to shoot me a dm. 

 

Thanks all, and have a great day!

 

Victor

 

Message 15 of 19

Joris.vd.Meulen
Collaborator
Collaborator
I don't get the order of your code.

What's the difference between defining all and my IFCExportConfiguration and the row below where you seem to update IFCExportOptions ... which is a standalone settings.

myIFCExportConfiguration.UpdateOptions(IFCExportOptions, ExportViewId);

//Process the IFC Export
doc.Export(Directory, doc, IFCExportOptions);
love python coding
0 Likes
Message 16 of 19

Dinesh.GoswamiQDCPR
Explorer
Explorer

Can you please share the full implantation. Thanks in advance

0 Likes
Message 17 of 19

Marcin_Klocek_JT6V9JKKZG2W
Explorer
Explorer

Alex, is it possible to programmatically load a predefined IFC export setup (.json file) and use it to export an .ifc model from Revit through API?

0 Likes
Message 18 of 19

victor.bastidas
Enthusiast
Enthusiast

Follow this code... It's posted here already (check line 10), with a solution to avoid the loading problem in the next comment. 

Solved: Re: IFC Export Options - Autodesk Community

0 Likes
Message 19 of 19

Marcin_Klocek_JT6V9JKKZG2W
Explorer
Explorer

I tried to use your approach, but for some reason it does not work. The Python script does run successfully in Dynamo graph, but the resulting IFC file is not as it should be, e.g. the objects (e.g. columns) do not have the BaseQuantities tab under Properties when the IFC file is opened in Navisworks, although  myIFCExportConfiguration.ExportBaseQuantities = True. Any idea what may be wrong in my code? The export_to_ifc function starts from line 114.

 

 

import clr
import os
import json
import System
from System.IO import Directory, Path

# Add necessary references
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.ApplicationServices import Application
from Autodesk.Revit.UI import TaskDialog

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitAPIIFC")
clr.AddReferenceToFileAndPath("C:\Program Files\Autodesk\Revit 2024\AddIns\IFCExporterUI\Autodesk.IFC.Export.UI.dll")
import BIM

# Get the active Revit document
doc = DocumentManager.Instance.CurrentDBDocument

central_path = doc.GetWorksharingCentralModelPath()
visible_path = ModelPathUtils.ConvertModelPathToUserVisiblePath(central_path)
file_name = Path.GetFileNameWithoutExtension(visible_path)

# Inputs
output_folder = IN[0]  # Folder to save exported files


def create_export_subfolder(base_folder, subfolder_name):
    export_path = os.path.join(base_folder, subfolder_name)
    if not os.path.exists(export_path):
        os.makedirs(export_path)
    return export_path

def export_to_nwc(doc, export_path, view_name="NWC"):
    # Find the 3D view by name for Navisworks export
    views = FilteredElementCollector(doc).OfClass(View).ToElements()
    navisworks_view = None
    for view in views:
        if view.Name == view_name and isinstance(view, View3D):
            navisworks_view = view
            break
    
    if navisworks_view is None:
        TaskDialog.Show("Error", "View named \"" + view_name + "\" not found.")
        return
        
    # Export to Navisworks
    nwc_export_options = NavisworksExportOptions()
    nwc_export_options.ExportScope = NavisworksExportScope.View
    nwc_export_options.ViewId = navisworks_view.Id
    nwc_export_options.ConvertElementProperties = True
    nwc_export_options.ConvertLinkedCADFormats = False
    nwc_export_options.ExportParts = True
    nwc_export_options.ExportRoomAsAttribute = False
    nwc_export_options.ExportRoomGeometry = False
    nwc_export_options.ExportUrls = False
    
    doc.Export(export_path, file_name, nwc_export_options)

def export_to_dwfx(doc, export_path, view_name="NWC"):
    # Get the view or sheet set named 'DWFX export' for DWFX export
    views = FilteredElementCollector(doc).OfClass(View).ToElements()
    DWFX_view = None
    for view in views:
    	if view.Name == view_name and isinstance(view, View3D):
            DWFX_view = view
            view_set=ViewSet()
            view_set.Insert(DWFX_view)
            
            """
            # Access the ViewSheetSetting for the document
            print_mgr = doc.PrintManager
            # print_mgr.SelectNewPrintDriver("Microsoft Print to PDF")
            print_mgr.PrintRange = PrintRange.Select
            
            # Get the ViewSheetSetting object
            view_sheet_setting = print_mgr.ViewSheetSetting
            
            # Create a new ViewSheetSet by providing the document and name
            view_sheet_setting.CurrentViewSheetSet.Views = view_set
            
            # Create a new ViewSheetSet named "DWFX_view_set"
            view_sheet_setting.SaveAs("DWFX_view_set")
            """
            
            break
    
    if DWFX_view is None:
        TaskDialog.Show("Error", "View named \"" + view_name + "\" not found.")
        return
        
    dwfx_export_options = DWFXExportOptions()
    dwfx_export_options.ExportObjectData = True
    dwfx_export_options.MergedViews = False
    dwfx_export_options.ExportingAreas = False
    dwfx_export_options.ExportTexture = True
    # dwfx_export_options.ExportTexture = Lossless
    dwfx_export_options.ExportOnlyViewId = DWFX_view.Id
    
    # Export using the selected view
    doc.Export(export_path, file_name, view_set, dwfx_export_options)

def export_to_ifc(doc, export_path, view_name="IFC"):
    
    views = FilteredElementCollector(doc).OfClass(View).ToElements()
    IFC_view = None
    for view in views:
    	if view.Name == view_name and isinstance(view, View3D):
        	IFC_view = view
         	break
    
    if IFC_view is None:
        TaskDialog.Show("Error", "View named \"" + view_name + "\" not found.")
        return
    
    ifc_export_options = IFCExportOptions()
    myIFCExportConfiguration = BIM.IFC.Export.UI.IFCExportConfiguration()
    myIFCExportConfiguration = BIM.IFC.Export.UI.IFCExportConfiguration.CreateDefaultConfiguration()
 
    # IFC Export Configuration options
    
    #### "General Content" Tab ####
    myIFCExportConfiguration.IFCVersion = IFCVersion.IFCCOBIE
    # myIFCExportConfiguration.ActiveViewId = IFC_view.Id
    myIFCExportConfiguration.SpaceBoundaries = 0
    myIFCExportConfiguration.SplitWallsAndColumns = False
   
    #### "Additional Content" Tab ####
    myIFCExportConfiguration.VisibleElementsOfCurrentView = True
    myIFCExportConfiguration.ExportRoomsInView = False
    myIFCExportConfiguration.Export2DElements = False
    myIFCExportConfiguration.ExportLinkedFiles = 0

    #### "Property Sets" Tab ####
    myIFCExportConfiguration.ExportIFCCommonPropertySets = True	
    myIFCExportConfiguration.ExportBaseQuantities = True
    myIFCExportConfiguration.ExportSchedulesAsPsets = False
    myIFCExportConfiguration.ExportSpecificSchedules = False
    
    #### "Level of Detail" Tab ####
    myIFCExportConfiguration.TessellationLevelOfDetail = 0.5
    
    #### "Advanced" Tab ####
    myIFCExportConfiguration.ExportPartsAsBuildingElements = True
    myIFCExportConfiguration.ExportSolidModelRep = False
    myIFCExportConfiguration.UseActiveViewGeometry = True
    myIFCExportConfiguration.UseFamilyAndTypeNameForReference = True
    myIFCExportConfiguration.Use2DRoomBoundaryForVolume = False
    myIFCExportConfiguration.IncludeSiteElevation = True
    myIFCExportConfiguration.StoreIFCGUID = True
    myIFCExportConfiguration.ExportBoundingBox = False
    
    # Apply the setup configuration
    myIFCExportConfiguration.UpdateOptions(ifc_export_options, IFC_view.Id)
    doc.Export(export_path, file_name, ifc_export_options)

def export_revit_model(base_directory):
    
    # Create subdirectories for NWC, DWF, and IFC exports
    nwc_folder = create_export_subfolder(base_directory, "nwc")
    dwfx_folder = create_export_subfolder(base_directory, "dwfx")
    ifc_folder = create_export_subfolder(base_directory, "ifc")
    
    # Begin transaction for export operations
    TransactionManager.Instance.EnsureInTransaction(doc)
    
    # Export to NWC
    export_to_nwc(doc, nwc_folder)
    
    # Export to DWFX
    export_to_dwfx(doc, dwfx_folder)
    
    # Export to IFC
    export_to_ifc(doc, ifc_folder)
    
    # Commit and end transaction
    TransactionManager.Instance.TransactionTaskDone()
    
    return "success"

OUT=export_revit_model(output_folder)

 

 

0 Likes