AnsweredAssumed Answered

ICommandBar.CreateMacroItem only for built in commands?

Question asked by thomasa on Apr 2, 2015


I am converting VBA code to a 10.2 addin. The code contains several context menus that are populated with IcommandBar.CreateMacroItem calling various different routines.

Called with a left click from from OnMouseDown the context menus are displayed but when I select an entry from the context menu I receive the following error message:


This method can only be called for built in commands


(or at least how I'guess how it should be translated from my OS message).

My code looks like this:


  Sub CreateContextMenuExample()

    Dim mApp As IApplication = TryCast(Me.Hook, ESRI.ArcGIS.Framework.IApplication)

    Dim commandBars As ESRI.ArcGIS.Framework.ICommandBars = mApp.Document.CommandBars

    Dim pCMenuBar As ICommandBar

    Dim pCmdItem As ICommandItem

    Dim sContextMenuName As String = "time period"

    Dim sPeriod()

    Dim sTitel As String

    Dim sMacroName As String

    Dim j As Integer


    sPeriod = {sContextMenuName, "period 1", "period 2"}


    pCMenuBar = commandBars.Create(sContextMenuName, esriCmdBarType.esriCmdBarTypeShortcutMenu)

    For j = 0 To UBound(sPeriod)                                   '

      sMacroName = "View.BVE.Period" & Trim(j)                                        'in VBA used to be "Project.ThisDocument.period" & Trim(j)

      sTitel = Trim(sPeriod(j))

      pCmdItem = pCMenuBar.CreateMacroItem(sTitel, j, sMacroName)

    Next j




  End Sub


I do not see any information in the documentation that ICommandBar.CreateMacroItem functionality has changed and works only with built in commands - and my code worked perfect in 10.0 VBA.

Did I overlook something?  Any help is appreciated!





Well, it appears that CreateMacroItem only works for VBA code... I do however not see how the same functionality could be obtained with .NET code. ICommandBar.Add requires an UID while want to start my own 'macros', that is sub routines with different, specific tasks. Any ideas on that would be extremely helpful! Cheers, Axel