<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Adding a button from an add-in to a TOC context menu in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/adding-a-button-from-an-add-in-to-a-toc-context/m-p/337673#M8854</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey all:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would like to add a button to a group layer context menu in the table of contents.&amp;nbsp; The button is from an add-in that also contains an extension.&amp;nbsp; Should be straight-forward enough.&amp;nbsp; The extension monitors the IActiveViewEvents_Event events and checks for a group layer being added by a specific name.&amp;nbsp; 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.&amp;nbsp; That mechanism is working.&amp;nbsp; The snippet of code that is failing is below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
if (String.Compare(topLayer.Name, "Testing") == 0)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set a uid for the group layer context menu.
&amp;nbsp;&amp;nbsp;&amp;nbsp; UID gUID = new UID();
&amp;nbsp;&amp;nbsp;&amp;nbsp; gUID.Value = "esriArcMapUI.GroupLayerContextMenu";&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // "{863A0D98-73DC-4331-8658-ED0E22247E36}"

&amp;nbsp;&amp;nbsp;&amp;nbsp; // Get the command bar denoting that context menu.
&amp;nbsp;&amp;nbsp;&amp;nbsp; ICommandBar groupLayerContextMenu = ArcMap.Application.Document.CommandBars.Find(gUID, false, false) as ICommandBar;

&amp;nbsp;&amp;nbsp;&amp;nbsp; // If there is a group layer context menu.
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (groupLayerContextMenu != null)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Change the UID to the add-in command.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gUID.Value = ThisAddIn.IDs.TestContextMenuButton;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ICommandItem cmd = groupLayerContextMenu.Find(gUID);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (cmd == null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmd = groupLayerContextMenu.Add(uid, ref missing);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 'Command not available' error thrown here...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmd.Refresh();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } 
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&amp;nbsp; Is there another way to add a button, or any item for that matter, when it lives in an add-in?&amp;nbsp; Or am I missing something simple?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 25 Mar 2014 14:04:22 GMT</pubDate>
    <dc:creator>dbrandon</dc:creator>
    <dc:date>2014-03-25T14:04:22Z</dc:date>
    <item>
      <title>Adding a button from an add-in to a TOC context menu</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/adding-a-button-from-an-add-in-to-a-toc-context/m-p/337673#M8854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey all:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would like to add a button to a group layer context menu in the table of contents.&amp;nbsp; The button is from an add-in that also contains an extension.&amp;nbsp; Should be straight-forward enough.&amp;nbsp; The extension monitors the IActiveViewEvents_Event events and checks for a group layer being added by a specific name.&amp;nbsp; 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.&amp;nbsp; That mechanism is working.&amp;nbsp; The snippet of code that is failing is below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
if (String.Compare(topLayer.Name, "Testing") == 0)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set a uid for the group layer context menu.
&amp;nbsp;&amp;nbsp;&amp;nbsp; UID gUID = new UID();
&amp;nbsp;&amp;nbsp;&amp;nbsp; gUID.Value = "esriArcMapUI.GroupLayerContextMenu";&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // "{863A0D98-73DC-4331-8658-ED0E22247E36}"

&amp;nbsp;&amp;nbsp;&amp;nbsp; // Get the command bar denoting that context menu.
&amp;nbsp;&amp;nbsp;&amp;nbsp; ICommandBar groupLayerContextMenu = ArcMap.Application.Document.CommandBars.Find(gUID, false, false) as ICommandBar;

&amp;nbsp;&amp;nbsp;&amp;nbsp; // If there is a group layer context menu.
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (groupLayerContextMenu != null)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Change the UID to the add-in command.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gUID.Value = ThisAddIn.IDs.TestContextMenuButton;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ICommandItem cmd = groupLayerContextMenu.Find(gUID);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (cmd == null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmd = groupLayerContextMenu.Add(uid, ref missing);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 'Command not available' error thrown here...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmd.Refresh();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } 
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&amp;nbsp; Is there another way to add a button, or any item for that matter, when it lives in an add-in?&amp;nbsp; Or am I missing something simple?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2014 14:04:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/adding-a-button-from-an-add-in-to-a-toc-context/m-p/337673#M8854</guid>
      <dc:creator>dbrandon</dc:creator>
      <dc:date>2014-03-25T14:04:22Z</dc:date>
    </item>
  </channel>
</rss>

