Determine which Command Item is selected on ArcMaps standard Command Bar

1924
4
Jump to solution
11-24-2014 10:02 AM
Highlighted
New Contributor III

I am working with Add-Ins in ArcMap using VS2010 and C#. I have a question in regards to ArcObjects ICommandBar and ICommandItem classes. I've looked at these and have been able to produce code, that on button click, will select or activate a specified command item. So I know somethings about command bars. My question is how would I go about determining which command Item is active on a Command Bar? I didn't see any helpful methods in which to do so.

I'm not all too sure which to even use at this point, between the ICommandBars object or the ICommandBar object. I've also discovered (I think) that the value/ref for the standard tool bar is:   "{5DEB1DB8-C2A9-11D1-B9A2-080009EE4E51}" .

I believe this is correct. Also, when I say standard tool bar, I mean the one with the select element tool on it.

Any help on this would be greatly appreciated. Thanks in advance.

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
New Contributor III

I finally found an answer to my problem. I was making this a little harder than it was and thinking about it way too hard. The code below can be used to return the currently selected tool in ArcMap (In my case I am returning the tooltip of the currently selected tool in my diagnostic window).

public static ICommandItem CurrentTool()

{

   IApplication _myApp = ArcMap.Application;

   string getToolTip = _myApp.CurrentTool.ToolTip;

   System.Diagnostics.Debug.Write("Tool Tip is: " + getToolTip);

  

   return _myApp.CurrentTool;

}

I call this function on a button click. So, When I launch ArcMap, I select a tool from the toolbar. I look into my diagnostic window and I'm able to see the tool tip for the selected tool. I will need to tweak a few things for my own benefit, but this would be the answer I am looking for. Hope this can be of some help to any one else.

View solution in original post

Reply
0 Kudos
4 Replies
Highlighted
Occasional Contributor II

Hi Jamari,

Is the CurrentTool property off IApplication what you're looking for?

Highlighted
New Contributor III

I had briefly looked at this property but not too much. I was able to set a tool on the command bar (Make active or make it highlighted, or execute it) using the code below.

UID pUID =  new UID();

myUid.Value = "esriArcMapUI.SelectTool";

IDocument ThisDoc = ArcMap.Application.Document;

ICommandBars CommandBars = ThisDoc.CommandBars as ICommandBars;

CommandBars.Find(myUid);

ICommandItem myItem = CommandBars.Find(myUid) as ICommandItem;

myItem.Execute();

This would select the "Select Element" tool on, perhaps, a button click. I'd call it from a function that needs to always run, so every time my function ran, the "Select Element" tool would be ran. But I need to know the current tool first so maybe I can do a conditional on my code and only run it in certain cases (Kind of went on a tangent). Anyways, from the info you provided me with, I believe I can get the current tool and do a comparison and then set the tool I need. I hope that made sense. The main thing for my overall,overall problem is getting the currently selected tool. Hopefully I can accomplish this with the info you've provided.

Thanks for your input.

Reply
0 Kudos
Highlighted
New Contributor III

I finally found an answer to my problem. I was making this a little harder than it was and thinking about it way too hard. The code below can be used to return the currently selected tool in ArcMap (In my case I am returning the tooltip of the currently selected tool in my diagnostic window).

public static ICommandItem CurrentTool()

{

   IApplication _myApp = ArcMap.Application;

   string getToolTip = _myApp.CurrentTool.ToolTip;

   System.Diagnostics.Debug.Write("Tool Tip is: " + getToolTip);

  

   return _myApp.CurrentTool;

}

I call this function on a button click. So, When I launch ArcMap, I select a tool from the toolbar. I look into my diagnostic window and I'm able to see the tool tip for the selected tool. I will need to tweak a few things for my own benefit, but this would be the answer I am looking for. Hope this can be of some help to any one else.

View solution in original post

Reply
0 Kudos
Highlighted
Occasional Contributor II

Short and sweet; I like it.  Glad you got this figured out.

Reply
0 Kudos