0

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 mehtods in which to do so. Any help on this would be greatly appreciated.

UID thisID = new UID(); 
thisID.Value = "esriArcMapUI.SelectTool"; 
IDocument ThisDoc = ArcMap.Application.Document; 
ICommandBars CommandBars = ThisDoc.CommandBars as ICommandBars; 
CommandBars.Find(thisID); 
ICommandItem myItem = CommandBars.Find(thisID) as ICommandItem; 

if (myItem.Execute() == true) 
{ 
 messagebox.show("My select element tool is selected");
}
user1898629
  • 329
  • 1
  • 4
  • 22
  • 1
    can you post the current code you are using so that we can see in regards to helping you determine if you are or are not doing something correctly..? thanks also have you seen this link http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//002300000068000000 – MethodMan Nov 20 '14 at 19:26
  • I don't have any concrete code for this particular issue written yet. I could pseudocode what I want if that would paint a btter picture for assistance from others. I have seen this link though. It searches for the item specified by the identifier. I wouldn't necessarily know which identifier is specified until a user clicks it. Which is essentially what I'm trying to do; obtain the command item that is clicked – user1898629 Nov 20 '14 at 19:45
  • can you come up with some actual code of what you are perhaps trying pseduocode really doesn't help me per say in this situation .. sorry – MethodMan Nov 20 '14 at 19:47
  • Ok, give me a few minutes and I'll see what I can conjure up – user1898629 Nov 20 '14 at 20:02
  • I need something like the following: UID thisID = new UID(); thisID.Value = "esriArcMapUI.SelectTool"; IDocument ThisDoc = ArcMap.Application.Document; ICommandBars CommandBars = ThisDoc.CommandBars as ICommandBars; CommandBars.Find(thisID); ICommandItem myItem = CommandBars.Find(thisID) as ICommandItem; if (myItem.Execute() == true) { messagebox.show("My select element tool is selected"); However there's a problem with my conditional statement. Getting an error: Operator '==' cannot be applied to operands of type void and bool – user1898629 Nov 20 '14 at 20:18
  • clearly my comment didnt format correctly but also to add from my last comment, I need this code inside of a function that is a void function. Or I guess, by definition, the ICommandItem.Execute() method is a void method, something like that – user1898629 Nov 20 '14 at 20:19
  • you need to update the original question and put the commented code there it's hard to read in its current state – MethodMan Nov 20 '14 at 20:33
  • @DJKRAZE I had updated the original post. Any possible insight or suggestions from the original code>? – user1898629 Nov 24 '14 at 16:12
  • 1
    try looking at this for some insight looks like instead of find you will need a while loop but not sure http://gis.stackexchange.com/questions/32038/how-to-find-all-icommanditem-instances-of-a-custom-button-command-in-an-arcmap-a also looks like your find() method is being implemented incorrectly – MethodMan Nov 24 '14 at 16:44
  • @DJKRAZE Yea, I'm still not finding a solution to my problem. Thanks for your help though – user1898629 Nov 24 '14 at 17:39

1 Answers1

0

I finally found an answer to my problem, with help from @DJKRAZE. 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("Current 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.

user1898629
  • 329
  • 1
  • 4
  • 22