Load IFC from Addin external command

Load IFC from Addin external command

Anonymous
Not applicable
1,271 Views
4 Replies
Message 1 of 5

Load IFC from Addin external command

Anonymous
Not applicable

Hi all, 

 

I am using Revit 2019 SDK and working with C#. I have read all existing forum topics related to OpenIFCDocument API and external blogs/websites referencing this API.

 

I have the following task:

1. manually start Revit and create a new empty project

2. create an Addin which loads an IFC file from local disk

 

To accomplish the above, I created an Addin and implemented the IExternalCommand interface. I can see and use my Addin in Revit (TaskDialog.Show works just fine).

 

My problem is the following:

When I call commandData.Application.Application.OpenIFCDocument("C:\\test.ifc", ifcImportOptions), Revit starts to load the IFC (I use IFCImportAction.Open), shows the loading progress bar, takes a minute or so to load, and when it is done loading, the model is not visible.

 

What am I missing here? Why is the model not visible (if I open the same model manually in Revit via IFC Open UI button, model is loaded ok and is visible)?


I'd appreciate any hints which could help me resolve this.

 

Thank you.

0 Likes
Accepted solutions (1)
1,272 Views
4 Replies
Replies (4)
Message 2 of 5

zhong_wu
Autodesk Support
Autodesk Support

When calling commandData.Application.Application.OpenIFCDocument("C:\\test.ifc", ifcImportOptions) with IFCImportAction.Open, Revit will actually open a Rvt project and import the IFC file into memory, it won't show it up in UI. 

 

If you want to make it visible, you may need to save the project into disk, and close it, then use UIApplication.OpenAndActivateDocument() to open and view it in Revit.   


John Wu
Developer Technical Services
Autodesk Developer Network


0 Likes
Message 3 of 5

Anonymous
Not applicable

Thank you for your input. I tried this, I saved the project (as a user, via UI), but when I open the saved project, the IFC model is still not visible. I can also see that the IFC file was never actually saved to disk from memory, as project file size is the same as that of an empty Revit project.

 

I'll rephrase my problem:

I need to open, and display in UI, an IFC file, while working in a new, empty Revit project, without any user interaction, other than users having to click on a button in my Addin which launches the IFC loading process.

 

Is this possible using current 2019 API?

 

Thank you.

Message 4 of 5

zhong_wu
Autodesk Support
Autodesk Support
Accepted solution

I just make an external command with the following sample code(please add error check yourself), I created a new project, and then run the command, I can successfully open the "test.rvt" file with the IFC file imported. No UI operation. 

            UIApplication app = commandData.Application;
            Document activeDoc = commandData.Application.ActiveUIDocument.Document;
            Document doc = app.Application.OpenIFCDocument("C:\\Users\\name\\Documents\\rvt5.ifc");
            doc.SaveAs("C:\\Users\\name\\Documents\\test.rvt");
            bool ret = doc.Close();            
app.OpenAndActivateDocument("C:\\Users\\name\\Documents\\test.rvt");

Please have a try and let me know your result.


John Wu
Developer Technical Services
Autodesk Developer Network


Message 5 of 5

Anonymous
Not applicable

Thank you, your solution got the job done.

 

Just an observation for any AutoDesk devs that may be involved with the API and reading this - it seems a bit unusual to have to import ifc/save/close/reopen the project when calling a method such as OpenIFCDocument. 

0 Likes