Wow! This works! Thanks a ton! Your example, and adjustments all make complete sense.Handy to have that Acme example as well... thanks for that pointer!Im no C# guy, so Ill post my vb.net version for anyone else to go over, including yourselfIn the config.esriaddinxas usual, create the menu, containing the items > button and Commands containing the button IDAutoload = true >> on the extensionisRootMenu = true >> on the MenuAnd here is the vb.net version that works.* note I used IndexObject value of 1 to place right beside the FILE choice on the main bar.Imports System.Windows.Forms
Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.esriSystem
Public Class Extension1
Inherits ESRI.ArcGIS.Desktop.AddIns.Extension
Private c_mainMenuID As String = "{1E739F59-E45F-11D1-9496-080009EEBECB}" ' Main menubar
Public Sub New()
End Sub
Protected Overrides Sub OnStartup()
WireDocumentEvents()
End Sub
Protected Overrides Sub OnShutdown()
End Sub
Private Sub WireDocumentEvents()
AddHandler My.ArcMap.Events.NewDocument, AddressOf ArcMapNewDocument
AddHandler My.ArcMap.Events.OpenDocument, AddressOf ArcMapOpenDocument
End Sub
Private Sub ArcMapNewDocument()
Try
LoadCustomMainMenu()
Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & "Details: " & ex.StackTrace, "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End Try
End Sub
Private Sub ArcMapOpenDocument()
Try
LoadCustomMainMenu()
Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & "Details: " & ex.StackTrace, "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End Try
End Sub
Private Sub LoadCustomMainMenu()
Dim mainMenuBar As ESRI.ArcGIS.Framework.ICommandBar = GetMainMenuBar()
' make sure we got the main menu bar
If mainMenuBar Is Nothing Then
Return
End If
' check if our custom menu is already there
Dim menuID As String = "FocusToolsToolbar_Addin_v10_ERCBMenu"
' ID of Add-In Root Menu
Dim cmdItem As ESRI.ArcGIS.Framework.ICommandItem = mainMenuBar.Find(menuID, False)
' skip out if custom menu already there
If cmdItem IsNot Nothing Then
Return
End If
System.Diagnostics.Debug.WriteLine("**** MENU ADDED ****")
' Add Menu, if needed
Dim uid As ESRI.ArcGIS.esriSystem.UID = New ESRI.ArcGIS.esriSystem.UIDClass()
uid.Value = menuID
Dim indexObj As [Object] = 1 ' Right beside FILE
' adds menu one spot in
Dim myMenu As ICommandBar = TryCast(mainMenuBar.Add(uid, indexObj), ICommandBar)
DirectCast(mainMenuBar, ESRI.ArcGIS.Framework.ICommandItem).Refresh()
End Sub
Private Function GetMainMenuBar() As ICommandBar
Try
'Grab the root menu bar
Dim uid As ESRI.ArcGIS.esriSystem.UID = New ESRI.ArcGIS.esriSystem.UIDClass()
uid.Value = c_mainMenuID
Dim mx As ESRI.ArcGIS.ArcMapUI.MxDocument = DirectCast(My.ArcMap.Application.Document, ESRI.ArcGIS.ArcMapUI.MxDocument)
Dim cmdBars As ESRI.ArcGIS.Framework.ICommandBars = mx.CommandBars
Dim x As ESRI.ArcGIS.Framework.ICommandItem = cmdBars.Find(uid, False, False)
Return TryCast(cmdBars.Find(uid, False, False), ICommandBar)
Catch
Return Nothing
End Try
End Function
End Class