/// <summary> /// Replaces the <paramref name="oldCommandUid" /> on the toolbar with the <paramref name="newCommandUid" /> /// </summary> /// <param name="source">The source.</param> /// <param name="newCommandUid">The new command uid.</param> /// <param name="oldCommandUid">The old command uid.</param> public static void Replace(this ICommandBar source, UID newCommandUid, UID oldCommandUid) { if (source != null) { ICommandItem command = source.Find(newCommandUid); if (command == null) { ICommandItem item = source.Find(oldCommandUid); if (item != null) { source.Add(newCommandUid, item.Index); item.Delete(); } } } }
public static void RemoveCommandItem(string menu, string command) { IApplication application = ArcMap.Application; IDocument document = application.Document; ICommandBars commandBars = document.CommandBars; var menuUid = new UID { Value = menu }; var contextMenu = commandBars.Find(menuUid) as ICommandBar; if (contextMenu != null) { var commandUid = new UID { Value = command }; ICommandItem commandItem = contextMenu.Find(commandUid); if (commandItem != null) { commandItem.Delete(); } } }