2

I would like to add a button to a group layer context menu in the table of contents. The button is from an add-in that also contains an extension. Should be straight-forward enough. The extension monitors the IActiveViewEvents_Event events and checks for a group layer being added by a specific name. When a layer is added, the IActiveViewEvents_ItemAddedEventHandler() is fired and calls a method that adds the button to the group layer context menus if the name is right. That mechanism is working. The snippet of code that is failing is below:

// Set a uid for the group layer context menu.
UID gUID = new UID();    
gUID.Value = "esriArcMapUI.GroupLayerContextMenu";   // "{863A0D98-73DC-4331-8658-ED0E22247E36}"

// Get the command bar denoting that context menu.
ICommandBar groupLayerContextMenu = ArcMap.Application.Document.CommandBars.Find(gUID, false, false) as ICommandBar;

// If there is a group layer context menu.
if (groupLayerContextMenu != null)
{
    // Change the UID to the add-in command.
    gUID.Value = ThisAddIn.IDs.TestContextMenuButton;

    ICommandItem cmd = groupLayerContextMenu.Find(gUID);

    if (cmd == null)
    {
        cmd = groupLayerContextMenu.Add(uid, ref missing);  'Command not available' error thrown here...
        cmd.Refresh();
    } 
}

To me, it seems that the command is not found because ICommandBar.Add(uid) is trying to dig for it in the registry but because it resides in an add-in it has not been added to the registry. Is there another way to add a button, or any item for that matter, when it lives in an add-in? Or am I missing something simple?

  • OK,let me simplify my question a little bit to see if I can get any input. If I try to run this code, I will get an error of "Command not Available" with a code of -2147221400. Googling the error code yields zero results. What exactly is this error telling me? – dbrandon Mar 27 '14 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.