ApplicationDocument |
This event is raised when Revit is just about to save the document with a new file name. Note that the first save of a newly created document will raise DocumentSavingAs rather than DocumentSaving 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.
This event is cancellable, except when it is raised during close of the application. Check the 'Cancellable' property of event's argument to see whether it is cancellable or not. When it is cancellable, call the 'Cancel()' method of event's argument to cancel it. Your application is responsible for providing feedback to the user about the reason for the cancellation.
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.
Another event DocumentSavedAs will be raised immediately after the document has been saved with a new file name.
public class DocumentSavingAs : IExternalApplication { /// <ExampleMethod> /// <summary> /// This method subscribes to DocumentSavingAs event. /// </summary> public Result OnStartup(UIControlledApplication application) { application.ControlledApplication.DocumentSavingAs += new EventHandler<DocumentSavingAsEventArgs>(CheckProjectStatusInitial); return Result.Succeeded; } /// <summary> /// Implement OnShutdown method of IExternalApplication interface to unregister subscribed event /// </summary> public Result OnShutdown(UIControlledApplication application) { // unregister subscribed event application.ControlledApplication.DocumentSavingAs -= new EventHandler<DocumentSavingAsEventArgs>(CheckProjectStatusInitial); return Result.Succeeded; } /// <summary> /// Event handler method for DocumentSavingAs event. This method will check the "Project Status" value, /// if it is null or empty string cancel the save as process. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">Event arguments that contains the event data.</param> private void CheckProjectStatusInitial(Object sender, DocumentSavingAsEventArgs args) { Document doc = args.Document; ProjectInfo proInfo = doc.ProjectInformation; // Project information is only available for project document. if (null != proInfo) { if (string.IsNullOrEmpty(proInfo.Status)) { // cancel the save as process. args.Cancel(); TaskDialog.Show("Revit","Status project parameter is not set. Save is aborted."); } } } /// </ExampleMethod> }