I am trying to use revit api to automate exporting IFC files. The revit model contains links to other revit models and each linked model has to be exported as a separate IFC file.
Using Revit 2014 API, I am able to get the linked document objects but here is the problem. The API to export IFC document requires that a transaction is open, but a transaction cannot be opened for linked documents. Is there a way to do this?
Example code:
FilteredElementCollector collector = new FilteredElementCollector(document); collector.OfClass(typeof(RevitLinkInstance)); foreach (Element elem in collector) { RevitLinkInstance instance = elem as RevitLinkInstance; Document linkDoc = instance.GetLinkDocument(); Transaction trans = new Transaction(linkDoc , "export"); trans.Start(); // this will fail linkDoc.Export(...); trans.Rollback(); }
Solved! Go to Solution.
Solved by R.van.den.Bor. Go to Solution.
Hello,
I did some research but could not find a lot of information on exporting linked documents but I wonder if you can get away with creating a transaction associated with the open document and then perform the export of the linked document. Can you please try this?
Thanks
Gopinath
Thanks for your answer. But that did not work. The document.Export() call needs an open transaction on the document object.
i did it like this.
First get a list of all links in the main document.
I order to open a link, you need to close the main document. But since you can't work in a zero document state, I open a dummy file.
So loop over the found linked files :
foreach(link ll in ListOfLinekdFIles)
{
Document OldCoc = _commData.Application.ActiveUIDocument.Document;
CurrDocument = _commData.Application.OpenAndActivateDocument(@"D:\Misc\RVTLink_dummy.rfa");
OldCoc.Close(false);
CurrDocument = _commData.Application.OpenAndActivateDocument(ll);
IFCExportOptions ifcOptions = new IFCExportOptions();
ifcOptions.FileVersion = IFCVersion.IFC2x3;
CurrDocument.Export(ProjectLocation, _filenaam, ifcOptions);
}
hope this helps, good luck