By Aaron Lu
In the forum, customer said he wants to close the active document and reopen it, he took the suggestion from Jeremy's blog, and had some events related questions, though I did not totally understand yet :(
As we know, to close document, we can use UIDocument.SaveAndClose() or Document.Close(), however, if the document is active, we got an InvalidOperationException: The active document may not be closed from the API.
So we need to use something else, Jeremy mentioned one way by sending "Ctrl+F4" message to Revit, i.e.:
SendKeys.SendWait( "^{F4}" );
Another way is, open and activate a placeholder document, and then close the original one, that's what the customer tried to do, and it works. To summary what the article is about, I used a shorter code snippet:
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);
Steps:
- Open and active the placeholder document
- Close the doc
- Open and activate the doc
- Close the placeholder document
So, we don't need any events for now :)