Message 1 of 17
Close Active Project/Document in REVIT 2016 using c# API

Not applicable
10-06-2017
11:26 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to close the active project(.rvt)/document in REVIT 2016 using c# API.
It is throwing below errors, I have tried multiple codes but all are throwing different exceptions.
I have added my code to open the document and the code I tried, please go through this and revert back with the solution ASAP.
The code I have written to open the document:
commandData.Application.OpenAndActivateDocument(@"D:\REVIT\IBG Projects\C12\C12_type C12 for export 12 sep central.rvt");
I tried below codes:
- SendKeys.SendWait("^{F4}"); - Not giving any error though not closing the document.
var placeholderFile = @"C:\placeholder.rvt"; var doc = commandData.Application.ActiveUIDocument.Document; var file = doc.PathName; var docPlaceholder = commandData.Application.OpenAndActivateDocument(placeholderFile); doc.Close(false); var uidoc = commandData.Application.OpenAndActivateDocument(file); docPlaceholder.Document.Close(false);
- commandData.Application.ActiveUIDocument.SaveAndClose();
I tried code from bellow two links
http://adndevblog.typepad.com/aec/2015/07/revitapi-close-active-document.html
http://thebuildingcoder.typepad.com/blog/2010/10/closing-the-active-document-and-why-not-to.html
Attached the error came on my screen after adding below code.
docPlaceholder.Document.Close(false);
Please reply ASAP.
Thanks