IFC export with custom setup possible?

@Chrissi

after install/update IFC Exporter addins, you should have this in the C:\ProgramData\Autodesk\ApplicationPlugins directory

1 Like

Hey Cyril,

yes, sorry, I checked it today once again and realised that for our 2024 version it uses the 2023 bundle.
In the code the version ( variable {1} ) thus points to a directory of a version 2024, not 2023.
Replacing the code to

ifc_bundle_path = “{0}\Autodesk\ApplicationPlugins\IFC 2023.bundle\Contents\2023”

solved the first issue. Another error occours:

but hey, one step closer!

image

try to replace

#Define the of a 3d view to export
exportViewId = None

by

#Define the of a 3d view to export
exportViewId = ElementId.InvalidElementId

I update my code here

1 Like

My laptop was doing alot of processing, it ran! …until…


you can simply adapt the 2nd python script with inputs (no need for a 3rd python script)

code Get IFC Configuration

import clr
import sys
import System

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
from Autodesk.Revit.Attributes import *
from Autodesk.Revit.DB.IFC import *


clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
sdkNumber = int(app.VersionNumber)


IFCExportConfiguration = None
IFCExportConfigurationsMap = None
pf_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86)
pf_data_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData)
ifc_bundle_path = "{0}\\Autodesk\\ApplicationPlugins\\IFC {1}.bundle\\Contents\\{1}".format(pf_data_path, sdkNumber)
if System.IO.Directory.Exists(ifc_bundle_path):
	# 1st try
	sys.path.append(ifc_bundle_path)
	clr.AddReference("IFCExporterUIOverride")
	from BIM.IFC.Export.UI import IFCExportConfigurationsMap, IFCExportConfiguration, IFCCommandOverrideApplication
else:
	ifc_addin_path = "{}\\Autodesk\\Revit {}\\AddIns\IFCExporterUI".format(pf_path, sdkNumber)
	if System.IO.Directory.Exists(ifc_addin_path):
		# 2nd try
		sys.path.append(ifc_addin_path)
		clr.AddReference("Autodesk.IFC.Export.UI")
		from BIM.IFC.Export.UI import IFCExportConfigurationsMap, IFCExportConfiguration, IFCCommandOverrideApplication

import json

ifc_dict_config = {}
if IFCExportConfigurationsMap is not None:
	idfdocA = IFCCommandOverrideApplication.TheDocument
	if idfdocA is None:
		propinfo = clr.GetClrType(IFCCommandOverrideApplication).GetProperty('TheDocument')
		propinfo.SetValue(None, doc)
	configurationsMap = IFCExportConfigurationsMap()
	configurationsMap.AddBuiltInConfigurations()
	configurationsMap.AddSavedConfigurations()
	for config in configurationsMap.Values:
		print(config.GetType())
		#dict_ifc_version_str = {"IFC_Version_str": config.IFCVersion.ToString() }
		#dict_config = json.loads(config.SerializeConfigToJson())
		# merge dictionaries
		#merge_dict_3 = dict(dict_ifc_version_str,**dict_config)
		ifc_dict_config[config.Name] = config
  
OUT = ifc_dict_config

code export ifc

import sys
import clr
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
from Autodesk.Revit.Attributes import*
from Autodesk.Revit.DB.IFC import*


# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
sdkNumber = int(app.VersionNumber)

myIFCExportConfiguration = IN[0]
view3d = UnwrapElement(IN[1])
folder_ifc_path = IN[2]
out_ifc_name = IN[3]

TransactionManager.Instance.EnsureInTransaction(doc)
options = IFCExportOptions()

#Define the of a 3d view to export
exportViewId = view3d.Id if view3d is not None else ElementId.InvalidElementId 

# Pass the setting of the myIFCExportConfiguration to the IFCExportOptions
myIFCExportConfiguration.UpdateOptions(options, exportViewId)
TransactionManager.Instance.TransactionTaskDone()

result = doc.Export(folder_ifc_path, out_ifc_name, options)

OUT = result
1 Like

It works, thanks alot!

Hello.The method used my @c.poupin works for a single view export with specific IFC configuration but it does not work when I try it with a list in the views Port (I would like to batch export multiple views with a specific IFC export configurations and the Genius Loci node does not allow it). Would someone have an idea of how I could modify the second script (answer above) for working with multiple 3D view export?
The actual node give me the error "

image

Thank you

I am 99% sure that Genuis Loci’s node does allow for multiple views. As i am using it for multiple views.
Judging from the error i assume your input is incorrect, Can you show the export node and everything that is going into the node?

Thank you for answering. yes Loci node allows multiple view export but does not allow to get a specific revit IFC Export configurations. I finally succeeded modifying the code like this.

import sys
import clr
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
from Autodesk.Revit.Attributes import*
from Autodesk.Revit.DB.IFC import*

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
sdkNumber = int(app.VersionNumber)

# Données d'entrée
myIFCExportConfiguration = IN[0]  # Configuration d'export IFC
views3d = [UnwrapElement(v) for v in IN[1]]  # Liste des vues 3D à exporter
folder_ifc_path = IN[2]  # Chemin du dossier où enregistrer les IFC
out_ifc_names = IN[3]  # Liste des noms de fichiers IFC pour chaque vue 3D

# Vérification de la cohérence des listes
if len(views3d) != len(out_ifc_names):
    raise ValueError("Le nombre de vues 3D et le nombre de noms de fichiers doivent être égaux.")

# Initialisation de la liste des résultats d'exportation
export_results = []

# Boucle sur chaque vue 3D pour effectuer l'exportation
for i, view3d in enumerate(views3d):
    if view3d is not None:
        out_ifc_name = "{}.ifc".format(out_ifc_names[i])  # Utilise le nom de fichier spécifique de la liste
        TransactionManager.Instance.EnsureInTransaction(doc)
        options = IFCExportOptions()

        # Récupère l'ID de la vue 3D à exporter
        exportViewId = view3d.Id if view3d is not None else ElementId.InvalidElementId

        # Applique la configuration IFC spécifiée à l'option d'exportation
        myIFCExportConfiguration.UpdateOptions(options, exportViewId)
        TransactionManager.Instance.TransactionTaskDone()

        # Effectue l'exportation et stocke le résultat
        result = doc.Export(folder_ifc_path, out_ifc_name, options)
        export_results.append(result)

# Sortie des résultats d'exportation
OUT = export_results
2 Likes

Hi, I had a similar problem as @Chrissi with the first Python script.
I switched to CPython3, pasted the latest script, and it worked.
However, the second Python script is causing an issue. I’ve already switched to CPython3 and pasted the latest script, but it’s giving me an error (see screenshot).
MISOS_Export IFC with config_WIP.dyn (44.8 KB)


Please, check your inputs

1 Like

Hello,

It turns out the issue was with the inputs. I was using a @Garbage_Collector dyn file, and it seems there might have been some incorrect labeling, which caused me to feed the script the wrong data. So yes, the problem was due to incorrect inputs.

With the help of ChatGPT, I was able to fix it and even improve the script for my needs. I needed it to handle two different IFC configurations: one for exporting the architectural model with rooms and another for the structural and interior elements without rooms.

Now, the script works great—I’ve set it up to use a list of views, file names, and IFC configurations, and everything is running smoothly.

I’m sharing the script here in case you’d like to take a look or give me some feedback.
MISOS_Export IFC with config_WIP.dyn (56.0 KB)

Thank you all again.

1 Like