A partner had used the API to open a Revit document programmatically using UIApplication.Application.OpenDocumentFile (FileName). He then, set the active view and the document got activated. Next, he tried to close this active document which is currently not supported by the API (as discussed in a blog post in this ADN AEC DevBlog as well as in Jeremy Tammik’s blog post). He wanted to find out if there are any methods to deactivate the document so that he could close the active document using API.
The workaround for closing the active document is to use the OpenAndActivateDocument() to open a new Revit document and then we can close the previous active document (which is what this partner/developer wanted to close with the API). This will deactivate the last opened document and thus we can close it using the Document.Close() method. The newly opened document would still need to closed manually at some point. The Revit File Upgrader uses this exact workaround to open a batch of Revit documents one by one and close the ones which have been upgraded to the newer version (with the documented limitation that the last opened document needs to be manually closed).

Leave a Reply