IFC Import and Conversion Journal Script

In the past, people repeatedly asked how to export a Revit model to IFC. The ability to programmatically save to IFC format has been added in the Revit 2011 API, as we can see from the section 'Export model to IFC' in the Revit API help file RevitAPI.chm What's New section, which notes that the new method Document.Export taking an IFCExportOptions argument exports the document to the Industry Standard Classes (IFC) format.

The inverse functionality, programmatically importing an IFC file into Revit, has not been frequently requested, nor is it currently available in the API. Being asked about this prompted me to try to nonetheless find a solution for this requirement, and I can now proudly present a workaround based on the journaling mechanism to solve it, which we already discussed as a possibility to invoke a Revit command in addition to the abovementioned IFC export.

The new IFC loading issue stems from the following question:

Question: I am trying to find a solution to achieve the following steps:

I am having trouble implementing the first step. The Application class does not seem to provide a dedicated method to open an IFC file and the generic OpenDocumentFile method does not work with IFC files. When I try to use it, it throws an exception saying that the file cannot be opened.

How can I load an IFC file into a Revit document with the API?

Answer: As mentioned above, the Revit 2011 API allows you to export to IFC format, but importing from IFC is not supported, and the OpenDocumentFile method does work with IFC files either.

I also tested opening an IFC file by simply specifying it on the Revit command line like this:

"C:\Program Files\Autodesk\Revit Architecture 
  2011\Program\Revit.exe" C:\tmp\walls.ifc

That results in a similar error message:

IFC open failed

Since we cannot open the IFC file using the API, nor specify it on the command line, the only alternative I can think of is to somehow make use of the user interface to do so. Happily, the journal file replay functionality provides the facility to repeat user interface actions.

Please note that the journaling mechanism was originally created for QA and regression tests, and its (mis-) use for automating tasks in Revit is completely unsupported. Still, if it works, you may find it useful nonetheless.

I designed and tested a workaround to make use of the journaling mechanism to load and convert the IFC file, and it performs well in my initial tests. This is what I did:

  1. Copy an IFC file to a specific hard-coded location, e.g. C:\tmp\import.ifc.
  2. Start up Revit.
  3. Open the file through the user interface.
  4. Save it to another hardcoded location, e.g. C:\tmp\export.rvt.
  5. Quit Revit.

Now look at the journal file that was automatically generated by this sequence of actions. It is the most recent file in the Journals subdirectory of the Revit main installation folder, e.g.

C:\Program Files\Autodesk\Revit Architecture 
  1. Save the journal file for future use, e.g. as C:\tmp\open_ifc_save_rvt_journal.txt.

Now you can programmatically achieve your IFC to RVT file conversion by the following steps:

  1. Copying the source IFC file to C:\tmp\import.ifc.
  2. Run Revit with the journal file as a command line argument, e.g.
"C:\Program Files\Autodesk\Revit 
  Architecture 2011\Program\Revit.exe" 
  1. The resulting target file has been saved as C:\tmp\export.rvt and can now be moved to its final filename and destination directory.

Linking the resulting RVT file to an opened document can be performed in a separate later step and is left as an exercise to the reader :-)

Response: With your very clear instructions, I tested what you suggest to automate the transformation from IFC to RVT format.

It works perfectly.

I did not investigate before this time the content of a Revit journal file. Hey, it is a vbs file working on an object class CrsJournalScript with LOTS of comments. What you suggest can be upgraded with writing our own script file and execute it in a shell from .NET to simulate the first part of the process I need to implement.

But I noticed that this kind of manipulation with journaling mechanism is unsupported. WWW tells me I am not the first to think about playing with journal files.

Thanks for this solution that seems to be the only one that could help me for now. On the other hand, I hope that IFC files will be accepted by the OpenDocumentFile method in future releases.