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:

  • Open an IFC file in Revit.
  • Save it as an RVT file.
  • Link the RVT file to an opened document.

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 FilesAutodeskRevit Architecture
2011ProgramRevit.exe" C:tmpwalls.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:tmpimport.ifc.
  2. Start up Revit.
  3. Open the file through the user interface.
  4. Save it to another hardcoded location, e.g. C:tmpexport.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 FilesAutodeskRevit Architecture
2011Journalsjournal.0186.txt
  1. Save the journal file for future use, e.g. as C:tmpopen_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:tmpimport.ifc.
  2. Run Revit with the journal file as a command line argument, e.g.

"C:Program FilesAutodeskRevit
Architecture 2011ProgramRevit.exe"
C:tmpopen_ifc_save_rvt_jounrnal.txt
  1. The resulting target file has been saved as C:tmpexport.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.


Comments

12 responses to “IFC Import and Conversion Journal Script”

  1. John Raiten Avatar
    John Raiten

    I must be missing something, How do i do step 3? Is step 3 opening the IFC, I get the standard error.

  2. Dear John,
    Step 3 is entirely your own responsibility. Step 1 is to copy the source IFC file to a fixed input file name and location, step 2 processes the input file and generates a fixed RVT output file. In step 3 you can access the RVT output file and do whatever you like with it.
    Cheers, Jeremy.

  3. John Raiten Avatar
    John Raiten

    My Journal file still gives me the error that it can not open the file.
    The following is what I have in it:
    Jrn.Command “Internal” , “Show or hide recent files , ID_STARTUP_PAGE”
    Jrn.Command “Internal” , “Open an existing project , ID_REVIT_FILE_OPEN”
    Jrn.Data “File Name” _
    , “IDOK”, “C:\tmp\import.ifc”
    Jrn.Data “WorksetConfig” _
    , “Custom”, 0
    Jrn.Command “Internal” , “Save the active project , ID_REVIT_FILE_SAVE”
    Jrn.Directive “DocSymbol” _
    , “[export.rvt]”

  4. Hi John,
    Did you create the file yourself, and are you trying to re-execute it on the same computer system, and are all file names absolutely guaranteed correct? Well, strange.
    As you know, Autodesk does not support journal files for automisation purposes, so I don’t think I will try to either.
    Good luck to you sorting it out!
    Cheers, Jeremy.

  5. Hector Diaz Avatar
    Hector Diaz

    Dear Jeremy:
    I launched a journal file as an argument executing RAC 2011 with the Command Prompt and it worked, however, I followed the same procedure for RAC 2012 (“C:\Program Files\Autodesk\Revit Architecture 2012\Program\Revit.exe” “C:\Users\Hector\Desktop\Journal\ journal.0171.txt”) but the next message appeared to me:
    Journal Error: The journal file could not be run to completion. Utilize care in saving any work as the project may be in an unstable state
    ENTER INTERACTIVE MODE
    Any idea why?
    What could I do to fix this issue?
    Thanks a lot
    Regards
    Hector

  6. Dear Hector,
    This ought to solve your issue:
    http://thebuildingcoder.typepad.com/blog/2011/11/loading-an-add-in-with-a-journal-file.html
    I hope this helps! Please let us know. Thank you!
    Cheers, Jeremy.

  7. Hector Diaz Avatar
    Hector Diaz

    Dear Jeremy,
    Thank you so much for your response, however I would like to run a journal file without the API, just with the command line since revit doesn’t have a batch mode (I would like to automate Revit with the journal file)…Is there another mean to run a journal file through the command line with Revit 2012?
    I really appreciate your help
    Thank you so much
    Regards…Héctor

  8. Dear Hector,
    The post I mentioned and other examples here on the blog all launch Revit with a journal file to execute from a command line batch file, without using the API.
    In addition to that, some of them show how a Revit add-in can be integrated into and executed automatically within this operation.
    If you have no need to run an add-in, just Revit itself, then everything is much simpler. The solution should be the same in principle. Just leave out the parts that you do not need.
    Cheers, Jeremy.

  9. Hector Diaz Avatar
    Hector Diaz

    Dear Jeremy,
    You mean that I leave out the addin manifest and the addin assembly; therefore, I just used the journal file and I launched it from the windows command line; however, the procedure didn’t work within windows 7-64bit. Also I installed Revit 2011 in this machine and the procedure didn’t work either. Nevertheless, I launched the journal file with Revit 2011 in a windows-32bit machine and it worked well. Do you think it’s about windows version?. The procedure was the same in all the cases:
    “C:\Program Files\Autodesk\Revit Architecture 2012\Program\Revit.exe” “C:\Users\Hector\Desktop\Journal\ journal.0171.txt”
    What do you think about that?
    Thank you so much for your help
    Regards
    Hector

  10. Hector Diaz Avatar
    Hector Diaz

    Dear Jeremy,
    I was investigating and I found this link at AUGI forum:
    http://forums.augi.com/showthread.php?t=111797
    I followed the directions and I was able to fix the issue
    Thank you so much
    Regards
    Hector

  11. Dear Hector,
    Congratulations on solving your issue and thank you for the link!
    Cheers, Jeremy.

  12. sabrina Avatar
    sabrina

    Dear Jeremy,
    Thanks a lot for you blog which is really helpful!
    I have the following problem concerning the IFC import in Revit: when I import an IFC file in Revit, the parameters (length, width) related to doors, windows disappear (not filled) though these values are present in the original ifc model and these elements are drawn in Revit(so the value should be known somewhere). Do you have any clue what the problem could be or in which direction should I search to access these values?
    thanks a lot in advance,
    Cheers,
    Sabrina

Leave a Reply to sabrinaCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading