Importing IFC through the Revit API in Dynamo takes a lot of time

Hi, I am trying to link an IFC-file in a revit project through a custom script from GeniusLoci in Dynamo and after some tries I made it work without error messages. It takes a lot of time even with smaller IFC-files, around 10 minutes, resulting in the program stopping responding, until it is done. When I try importing the same IFC-file manually, using the Insert tab in Revit it takes max 20 seconds or so. The script that I have used is attached below, and the input is a filepath to the relevant ifc-file. I use the id to insert in a dictionary to later be able to call this ifc-link, and to be able to select it in case it is already existing, but that is a later project. Is there any obvious issues with my script? Thanks in advance for all the help.

#Alban de Chasteigner 2019
#twitter : @geniusloci_bim
#geniusloci.bim@gmail.com
import clr
import Revit
import Autodesk
import System

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference('RevitAPIIFC')
from Autodesk.Revit.DB.IFC import *

clr.AddReference("RevitNodes")
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitServices")

from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

if isinstance(IN[0], list) : IFCfilepaths = IN[0] 
else : IFCfilepaths = [IN[0]]

placement = System.Enum.Parse(ImportPlacement, IN[1])
linkInstances = []

IFCoptions = Autodesk.Revit.DB.IFC.IFCImportOptions()
IFCoptions.Intent = IFCImportIntent.Reference

saveAsOpt = SaveAsOptions()
saveAsOpt.OverwriteExistingFile = True

RVToptions = RevitLinkOptions(True)
ids =[]

TransactionManager.Instance.EnsureInTransaction(doc)


for IFCfilepath in IFCfilepaths :
	IFCdoc = app.OpenIFCDocument(IFCfilepath,IFCoptions)
	
	RVTfilepath = IFCfilepath + ".rvt"
	IFCdoc.SaveAs(RVTfilepath, saveAsOpt)
	IFCdoc.Close(False)
	
	loadResult = RevitLinkType.CreateFromIFC(doc,IFCfilepath,RVTfilepath,False,RVToptions)
	
	linkInstances.append(RevitLinkInstance.Create(doc, loadResult.ElementId, placement))
	ids.append(loadResult.ElementId)
TransactionManager.Instance.TransactionTaskDone()


OUT = ids

It seems like it is the parsing step that it gets (almost) stuck. In other words, when we open the IFCDocument in IFCdoc = app.OpenIFCDocument(IFCfilepath,IFCoptions)

Hi,

Try to modify the IFCImportOptions in OpenIFCDocument(IFCfilepath, IFCoptions) and see if it is faster.
Add this line in the Python script : IFCoptions.Action = IFCImportAction.Link

1 Like

Hey, the man himself! Like you said I tried adding that line in the script, as seen below. But now I get an error message: "InternalException : Failed to create a new document at Autodesk.Revit.ApplicationServices.Application.OpenIFCDocument(String fileName, IFCImportOptions importOptions) [’ File “”, line 54, in \n’] " I also tried to uncomment #IFCoptions.Action = IFCImportAction.Open and it didn’t change anything either. Thank you for looking into this!

#Alban de Chasteigner 2019
#twitter : @geniusloci_bim
#geniusloci.bim@gmail.com

import clr
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitAPIIFC')
from Autodesk.Revit.DB.IFC import *

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

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

import sys
sys.path.append(r"C:\Program Files (x86)\IronPython 2.7\Lib")
import System

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

if isinstance(IN[0], list) : IFCfilepaths = IN[0] 
else : IFCfilepaths = [IN[0]]

placement = System.Enum.Parse(ImportPlacement, IN[1])
linkInstances = []

IFCoptions = Autodesk.Revit.DB.IFC.IFCImportOptions()
#IFCoptions.Action = IFCImportAction.Open
IFCoptions.Action = IFCImportAction.Link #< The new line added 
IFCoptions.Intent = IFCImportIntent.Reference

#IFCoptions.AutoJoin=True
#IFCoptions.AutocorrectOffAxisLines = True
#IFCoptions.ForceImport=True

saveAsOpt = SaveAsOptions()
saveAsOpt.OverwriteExistingFile = True

RVToptions = RevitLinkOptions(True)

TransactionManager.Instance.EnsureInTransaction(doc)
#Open the IFC document using the default options :
for IFCfilepath in IFCfilepaths :
	IFCdoc = app.OpenIFCDocument(IFCfilepath,IFCoptions)
	#IFCdoc = app.OpenIFCDocument(IFCfilepath)
	#Save the Revit file in the same folder:
	#RVTfilepath = IFCfilepath.replace(".ifc", ".rvt", 1)
	RVTfilepath = IFCfilepath + ".rvt"
	IFCdoc.SaveAs(RVTfilepath, saveAsOpt)
	IFCdoc.Close(False)
	loadResult = RevitLinkType.CreateFromIFC(doc,IFCfilepath,RVTfilepath,False,RVToptions)
	linkInstances.append(RevitLinkInstance.Create(doc, loadResult.ElementId, placement))
TransactionManager.Instance.TransactionTaskDone()

if isinstance(IN[0], list): OUT = linkInstances
else: OUT = linkInstances[0]

Sorry, I might have clicked the wrong button and made another comment but did not answer to your comment. I tried your fix, but then I instead got an InternalException as I said below. Thank you so much for popping in to help.

Hi,

I was on vacation and hadn’t the opportunity to verify my suggestion but I just checked and indeed the IFCImportAction.Link option triggers an error.

IFCImportAction.Open is the default option so adding or removing it doesn’t change anything.
For me, the main possibility is to modify the IFC options to gain speed.
I did an internet search on forums but there are very few suggested indications.

Maybe try CreateFromIFC Method (Document, ExternalResourceReference, String, Boolean, RevitLinkOptions) and see if there is a difference.

What is the difference to how that method is implemented in the link ifc node already? In this line:
loadResult = RevitLinkType.CreateFromIFC(doc,IFCfilepath,RVTfilepath,False,RVToptions)