// // (C) Copyright 2003-2022 by Autodesk, Inc. // // Permission to use, copy, modify, and distribute this software in // object code form for any purpose and without fee is hereby granted, // provided that the above copyright notice appears in all copies and // that both that copyright notice and the limited warranty and // restricted rights notice below appear in all supporting // documentation. // // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE // UNINTERRUPTED OR ERROR FREE. // // Use, duplication, or disclosure by the U.S. Government is subject to // restrictions set forth in FAR 52.227-19 (Commercial Computer // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) // (Rights in Technical Data and Computer Software), as applicable. // using System; using Autodesk.Revit.UI; namespace Revit.SDK.Samples.ContextMenu.CS { /// /// Implements the Revit add-in interface IExternalApplication, /// register context menu creators implemented by user with application full class name. /// public class ContextMenuApplication : IExternalApplication { #region IExternalApplication Members /// /// Implement this method to implement the external application which should be called when /// Revit starts before a file or default template is actually loaded. /// /// An object that is passed to the external application /// which contains the controlled application. /// Return the status of the external application. /// A result of Succeeded means that the external application successfully started. /// Cancelled can be used to signify that the user canceled the external operation at /// some point. /// If Failed is returned then Revit should inform the user that the external application /// failed to load and the release the internal reference. public Result OnStartup(UIControlledApplication application) { try { // register context menu creator. application.RegisterContextMenu(typeof(ContextMenuApplication).FullName, new ContextMenuCreator()); return Result.Succeeded; } catch (Exception ex) { TaskDialog.Show("ContextMenu Sample", ex.ToString()); return Result.Failed; } } /// /// Implement this method to implement the external application which should be called when /// Revit is about to exit, Any documents must have been closed before this method is called. /// /// An object that is passed to the external application /// which contains the controlled application. /// Return the status of the external application. /// A result of Succeeded means that the external application successfully shutdown. /// Cancelled can be used to signify that the user canceled the external operation at /// some point. /// If Failed is returned then the Revit user should be warned of the failure of the external /// application to shut down correctly. public Result OnShutdown(UIControlledApplication application) { //remove events return Result.Succeeded; } #endregion } }