Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Exporting IFC for linked documents

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
chris.inv
1620 Views, 4 Replies

Exporting IFC for linked documents

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();
}

 

Tags (1)
4 REPLIES 4
Message 2 of 5
gopinath.taget
in reply to: chris.inv

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

Message 3 of 5
chris.inv
in reply to: gopinath.taget

Thanks for your answer. But that did not work. The document.Export() call needs an open transaction on the document object.

Message 4 of 5
R.van.den.Bor
in reply to: chris.inv

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

Kind regards,
Remy van den Bor
ICN Solutions B.V.
Liked this post or found it usefull, don't forget the Kudo It won't hurt (at least not me).
Message 5 of 5
chris.inv
in reply to: R.van.den.Bor

Good idea. Thanks!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community