ApplicationDocument |
This event is raised immediately after Revit has finished opening a document. It is raised even when document opening failed or was cancelled (during DocumentOpening event).
Handlers of this event are permitted to make modifications to any document (including the active document), except for documents that are currently in read-only mode.
Check the 'Status' field in event's argument to see whether the action itself was successful or not.
This event is not cancellable, for the process of opening document has already been finished.
If the action was not successful, the document may not be modified and new transactions may not be started.
The following API functions are not available for the current document during this event:
Exception InvalidOperationException will be thrown if any of the above methods is called during this event.
public class Application_DocumentOpened : IExternalApplication { /// <ExampleMethod> /// <summary> /// Implement this method to subscribe to event. /// </summary> public Result OnStartup(UIControlledApplication application) { try { // Register event. application.ControlledApplication.DocumentOpened += new EventHandler <Autodesk.Revit.DB.Events.DocumentOpenedEventArgs>(application_DocumentOpened); } catch (Exception) { return Result.Failed; } return Result.Succeeded; } /// <summary> /// Implement OnShutdown method of IExternalApplication interface to unregister subscribed event /// </summary> public Result OnShutdown(UIControlledApplication application) { // remove the event. application.ControlledApplication.DocumentOpened -= application_DocumentOpened; return Result.Succeeded; } /// <TrivialCode> /// Code ID: 501 /// For DocumentOpened class description /// </TrivialCode> /// <description> /// This sample demonstrates how to subscribe to the DocumentOpened event and modify the model in the event handler method. /// </description> /// <summary> /// This is the event handler. We modify the model. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="args"></param> public void application_DocumentOpened(object sender, DocumentOpenedEventArgs args) { // get document from event args. Document doc = args.Document; // Following code snippet demonstrates support of DocumentOpened event to modify the model. // Because DocumentOpened supports model changes, it allows user to update document data. // Here, this sample assigns a specified value to ProjectInformation.Address property. // User can change other properties of document or create(delete) something as he likes. // // Please note that ProjectInformation property is empty for family document. // So please don't run this sample on family document. using (Transaction transaction = new Transaction(doc, "Edit Address")) { if (transaction.Start() == TransactionStatus.Started) { doc.ProjectInformation.Address = "United States - Massachusetts - Waltham - 1560 Trapelo Road"; transaction.Commit(); } } } /// </ExampleMethod> }