POST
|
Hey all: 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:
if (String.Compare(topLayer.Name, "Testing") == 0)
{
// 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?
... View more
03-25-2014
07:04 AM
|
0
|
0
|
263
|
POST
|
Hey all: I am converting some code developed for ArcGIS 9.x to ArcGIS 10. It deals with adding a collection of toolbars to a toolbar control that is added to a stand alone application. The original code looks something like this:
UID uid = new UIDClass();
for (int i = 0; i < toolbarList.Count; i++)
{
try
{
uid.Value = toolbarList.progid;
AxToolbarControl toolbarCtrl = new AxToolbarControl();
((System.ComponentModel.ISupportInitialize)(toolbarCtrl )).BeginInit();
toolbarCtrl .Margin = new System.Windows.Forms.Padding(4);
Controls.Add(toolbarCtrl);
((System.ComponentModel.ISupportInitialize)(toolbarCtrl )).EndInit();
toolbarCtrl.AddToolbarDef(uid, -1, true, 4, esriCommandStyles.esriCommandStyleIconOnly);
...
}
catch(Exception ex)
{
MessageBox.Show("Cannot add toolbar [" + toolbarList.progid.ToString() + "]");
}
}
With 9.3 this code would work but now it is not. I don't know if the problem is with this code or the first toolbar (I have only converted the first one) itself however, I am able to pull the toolbar into ArcMap 10 and it displays just fine. If I take the first two commands from the toolbar in question and add them using toolbarCtrl.AddItem(item), the toolbar loads just fine. Any ideas that might get this going again? Thanks.
... View more
08-07-2012
08:52 AM
|
0
|
0
|
278
|
Online Status |
Offline
|
Date Last Visited |
02-10-2021
02:12 PM
|