Hello,
I am trying to export a model including its linked models. When I export from the IFC exporter UI in Revit, it works fine creating separate files for the main model and the linked models. However, exporting from the code while setting the IFC export option "ExportLinkedFiles" to "true" does not produce the linked model IFC, only the model in the main document is exported.
This is the snippet of code that is relevant, it's inside a function and "activeDoc" is passed as argument representing the document that's to be exported:
IFCExportOptions ifcOptions = new IFCExportOptions();
BIM.IFC.Export.UI.IFCExportConfiguration myIFCExportConfiguration = BIM.IFC.Export.UI.IFCExportConfiguration.CreateDefaultConfiguration();
myIFCExportConfiguration.SitePlacement = 3;
myIFCExportConfiguration.ExportLinkedFiles = true;
ElementId ExportViewId = ElementId.InvalidElementId;
myIFCExportConfiguration.UpdateOptions(ifcOptions, ExportViewId);
string outputTitle = activeDoc.Title + "_temp_export";
string outputPath = "C:\\Projects\\myProject";
using (Transaction tr = new Transaction(activeDoc))
{
tr.Start("Export Ifc");
activeDoc.Export(outputPath, outputTitle, ifcOptions);
TransactionStatus s = tr.Commit();
if (TransactionStatus.Committed != s)
{
Log.Error("Transaction " + tr.GetName() + " did not commit. Status = " + s.ToString());
}
}
Before this code, we used to open each linked document separately in a loop, export the IFC then pass to the next until all are exported. However, we had some issues with the coordinates and none of the option for SitePlacement were giving the desired result, that's why I wanted to give this a shot since it seemed that it was supported natively by the IFC exporter.
Found that someone else has reported a similar issue here: https://github.com/Autodesk/revit-ifc/issues/222#issuecomment-1607934349
Thank you in advance for any help.
I asked the development team for you.
The development team replied: I'll address the post with the code snippet, since that's a specific implementation. If the code in the other link has a much different implementation, then this might not apply.
What I see in the snippet, in essence (within a Transaction):
activeDoc.Export(outputPath, outputFile, ifcOptions);
My primary question, since it's not really clear to me: what is the activeDoc?
Is it one of the Linked Documents (and then this code might be in a loop)?
Or is it the Host Document?
The reason I'm asking is that most of the implementations I've seen follow the pattern:
hostDocument.Export() --> exports the host document.
for each Linked Document linkDoc
{
linkDoc.Export() --> exports the linked document.
}
In other words, Export the Host Document, followed by all the Linked Documents. At each step, you can generate a different file/path name.
Perhaps this is what you are doing. Please let me know if this is the case.
Thanks Jeremy for reaching out to the development team.
Sorry if it was not clear, activeDoc is the host document. In the UI IFC exporter, while the host document is open, the IFC exporter has an option 'Export linked files as seperate IFCs' (image below) which I tested and it works. In the snippet I showed I was trying to achieve the same thing from the code but it doesn't work. Normally, the API code on the backend (I suppose) would open the linked files in a loop and do the export.
The implementation you mentioned looks like what we had before and it works, however, I was debugging an issue with a specific project that had the exported linked IFC not having its coordinates relative to the Internal Origin even when "SitePlacement" is set to Internal. That has lead me to try and change the way linked files export is done to the one I described here, for me it looked like a more proper way since it is replicating what's being done from the UI, hoping it might resolve the issue with coordinates but it turned out into a bigger issue of not exporting anything.
Thanks again for your help, I guess I'll revert back to the previous code since it is closest to what's working. It seems that the conclusion is also that "ExportLinkedFiles" that is exposed in the IFCExportConfiguration (see it here) is not working as intended.
Thanks Jeremy for reaching out to the development team.
Sorry this was not clear, activDoc is the Host Document.
The initial code I had and was working actually was exporting the linked files using an implementation similar to the one you mentioned (loops through linked files and exports them). I was having an issue with a specific project that has the Linked Document exported with wrong coordinates, I wanted it relative to Internal Origin but it is not even though "SitePlacement" was set to Internal. At some point in my debugging, I wanted to try this other approach for exporting the linked documents because it looked more in line with what the IFC UI Exporter does. To do this from UI IFC Export, you open the Host Document and select the option shown in the image below (this normally maps to setting "ExportLinkedFiles" to "true").
I guess I will revert back to the previous code and take another route for fixing the coordinates issue. That being said, it looks that "ExportLinkedFiles" that is exposed in "IFCExportConfiguration" (see here) is not working as intended (summary for this attribute was left blank unlike the others, so maybe it is not actually implemented, looks suspicious..).
Thanks again Jeremy for your help!
Thank you for the explanation. Yes, a different approach will probably be required to adjust individual coordinate settings. I passed on your suspicion to the powers that be...
The development team replies: It is definitely implemented, but it is also out of date. There are 4 options now: don't export links, export as separate files, export in same file with same IfcProject, and export in same file with same IfcSite. So, perhaps that's the issue here, that you are trying to supply the old Boolean argument when it is now an enum.
Can't find what you're looking for? Ask the community or share your knowledge.