Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IFC Export Options

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
Anonymous
8451 Views, 15 Replies

IFC Export Options

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.

Tags (2)
Labels (1)
15 REPLIES 15
Message 2 of 16
jeremytammik
in reply to: Anonymous

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

Message 3 of 16
Anonymous
in reply to: Anonymous

@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 16
Anonymous
in reply to: Anonymous

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.

Message 5 of 16
juan_hoyos4
in reply to: Anonymous

Is there an option to export to ifczip?

Message 6 of 16
jeremy_tammik
in reply to: juan_hoyos4

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
Message 7 of 16
strsuraj
in reply to: juan_hoyos4

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

Message 8 of 16
H.echeva
in reply to: Anonymous

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

Message 9 of 16
H.echeva
in reply to: Anonymous

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

Message 10 of 16
fritz.sandner
in reply to: Anonymous

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
Message 11 of 16
Message 12 of 16
jacopo_chiappetti
in reply to: Anonymous

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 16
victor.bastidas
in reply to: Anonymous

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 16

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 16
Joris.vd.Meulen
in reply to: Anonymous

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
Message 16 of 16

Can you please share the full implantation. Thanks in advance

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups


Rail Community