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.
Solved! Go to Solution.
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.
Solved! Go to Solution.
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
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
@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.
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.
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.
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
@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.
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.
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.
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
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.
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.
Is there an option to export to ifczip?
Is there an option to export to ifczip?
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.
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.
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
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
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
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
https://thebuildingcoder.typepad.com/blog/2012/07/multi-version-add-in.html
https://thebuildingcoder.typepad.com/blog/2012/07/multi-version-add-in.html
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"
}
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"
}
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
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
Just if anyone eeeeever gets to this point of fighting agains the null pointer exception...
It gets created by this line:
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
Just if anyone eeeeever gets to this point of fighting agains the null pointer exception...
It gets created by this line:
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
Can you please share the full implantation. Thanks in advance
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.