programmatically add an item into an ArcMap 10 out-of-box context menu?

2227
1
Jump to solution
06-21-2012 01:11 PM
SuiHuang
Occasional Contributor II
Hi Everybody:

    I ran the following code to add a command into the Data View Context Menu (the one that pops up after right clicking the map data view, as attached picture) of ArcMap. The command with the icon was added to the menu, but once I run this command after that I will get an exception.
    If I do the samething manually by "Customize"==>"Customize Mode" and then drag-drop the command into the "Context Menus" in "Toolbars" tab, then the command will still work fine.
    What is wrong in my code? Thank you!

UID contextMenuId = new UIDClass(); Object optionalIndex = Type.Missing; contextMenuId.Value = "{3846A5B5-D3F8-44CB-BFA3-A5C30F4E535F}"; //the data view context menu ICommandBar commandBar = _mApplication.Document.CommandBars.Find(contextMenuId) as ICommandBar; contextMenuId.Value = "esriArcMapUI.ZoomInFixedCommand"; commandBar.Add(contextMenuId, ref optionalIndex);


[ATTACH=CONFIG]15415[/ATTACH]
0 Kudos
1 Solution

Accepted Solutions
SuiHuang
Occasional Contributor II
I tried the code again and it works fine this time. Maybe that`s because I screw the system up before...

Hi Everybody:

    I ran the following code to add a command into the Data View Context Menu (the one that pops up after right clicking the map data view, as attached picture) of ArcMap. The command with the icon was added to the menu, but once I run this command after that I will get an exception.
    If I do the samething manually by "Customize"==>"Customize Mode" and then drag-drop the command into the "Context Menus" in "Toolbars" tab, then the command will still work fine.
    What is wrong in my code? Thank you!

UID contextMenuId = new UIDClass(); Object optionalIndex = Type.Missing; contextMenuId.Value = "{3846A5B5-D3F8-44CB-BFA3-A5C30F4E535F}"; //the data view context menu ICommandBar commandBar = _mApplication.Document.CommandBars.Find(contextMenuId) as ICommandBar; contextMenuId.Value = "esriArcMapUI.ZoomInFixedCommand"; commandBar.Add(contextMenuId, ref optionalIndex);


[ATTACH=CONFIG]15415[/ATTACH]

View solution in original post

0 Kudos
1 Reply
SuiHuang
Occasional Contributor II
I tried the code again and it works fine this time. Maybe that`s because I screw the system up before...

Hi Everybody:

    I ran the following code to add a command into the Data View Context Menu (the one that pops up after right clicking the map data view, as attached picture) of ArcMap. The command with the icon was added to the menu, but once I run this command after that I will get an exception.
    If I do the samething manually by "Customize"==>"Customize Mode" and then drag-drop the command into the "Context Menus" in "Toolbars" tab, then the command will still work fine.
    What is wrong in my code? Thank you!

UID contextMenuId = new UIDClass(); Object optionalIndex = Type.Missing; contextMenuId.Value = "{3846A5B5-D3F8-44CB-BFA3-A5C30F4E535F}"; //the data view context menu ICommandBar commandBar = _mApplication.Document.CommandBars.Find(contextMenuId) as ICommandBar; contextMenuId.Value = "esriArcMapUI.ZoomInFixedCommand"; commandBar.Add(contextMenuId, ref optionalIndex);


[ATTACH=CONFIG]15415[/ATTACH]
0 Kudos