Importing IFC files in bulk with Dynamo into Revit

Hello all

Trying to ease our process into our collaboration with Civil 3D users and Revit by working with Revit.

Since our Civil 3D users are exporting each network per 1 IFC files, this can get teadious when linking an IFC file in Revit.

Now I managed to write a little python script code and i’m not quite sure how to work with the IFCImportOptions class

But hey, i’m here to learn so i’m reaching out for guidance here :slight_smile:

Here’s my code :

import clr
import System
import os

# Import Revit API
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIIFC')
from Autodesk.Revit.DB.IFC import *

# Import RevitServices
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

# Input directory path
directory_path = IN[0]

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

# Get all IFC files in the directory
ifc_files = [f for f in os.listdir(directory_path) if f.endswith('.ifc')]

# Initialize the list to store results
imported_files = []

# Start a transaction to import IFC files
TransactionManager.Instance.EnsureInTransaction(doc)

for ifc_file in ifc_files:
    ifc_path = os.path.join(directory_path, ifc_file)
    try:
        # Create IFC import options
        options = IFCImportOptions()
        
        # Import the IFC file
        result = doc.Import(ifc_path, options)
        
        imported_files.append(result)
    except Exception as e:
        # Append error message in case of failure
        imported_files.append(str(e))

TransactionManager.Instance.TransactionTaskDone()

# Output the result
OUT = imported_files

I think this may be a big learning curve for me right now but, am i going in the right direction with this approach ?

Well I really decided to initially make my life hard with that python script.

When browsing i noticed that the Genius Loci package has a Link IFC node.

The only thing is that I get a nul when trying to use it :

I’m not the only one several people has the same resulat as me

Anyone knows why ?

Ok, i’m scratching on this subject and playing around right now.

I wonder which version of IFC is supported by the Genius Loci Link IFC node ?

The null happens when its IFC4x3_ADD2, then the IFC4x3 gives tons of loops in a single IFC file.

Hi,

In the Revit API, the IFC 4x3 format only exists in Revit 2024.
So if you are using a previous Revit version, there is a good chance that it will fail with the Link IFC node which is dependent on the API.

That’s pretty important information to know

Thank you for the heads up

Do you know if there’s a matrix that exist that shows which versions are supported ?

Not to my knowledge.

It is also possible to import the IFC Exporter .dll (the addin) which adds functionality.
However, the Python custom node only uses the Revit API.

2 Likes

Gotcha

So when i use the traditional method to link an IFC my IFC 4x3 is linked correctly without error msg but with the “Link IFC” node it gives error messages

So i’ve retried exporting the IFC to IFC4 so it will be supported by the node and here’s the *.log.html dump i’ve got

It only parsed one IFC and didnt link it because of the error :

Trying to understand why it doesnt link everything right now because it should work

Hi @Alban_de_Chasteigner ,

Does the #9 and #10 errors stops the node Link IFC ?

The ones related to AREAUNIT

I’ve tried multiple testings and when i monitor the directory where the IFC files are i can see the Dynamo creates a log.html and the ifc.rvt file on only the first IFC file and then finishes.

Opening that only log report says there’s 2 errors related to :
AREAUNIT METRE
VOLUMEUNIT METRE

Not sure if meters written in french “METRE” impacts something in the IFC ?