AnsweredAssumed Answered

Accessing/Using ArcMaps Commands via C#

Question asked by Jamari_L_Powers on Nov 18, 2014
Latest reply on Nov 19, 2014 by Jamari_L_Powers

I am working with ArcObjects, Arc Map and C#. There is a tool used in ArcMap to select elements on a map document (esriArcMapUI.SelectTool). I want to be able to use this so that on a button click from my form, this tool becomes the currently active tool. I have looked at examples but I keep getting a Null reference object error when I click my button. Here's what I have so far:




   public class myButton : Button


      IApplication app;


       public myButton()




protected override void onClick()




        ICommandBars documentBars = app.Document.CommandBars;

        UID cmdID = new UIDClass();

        cmdID.Value = "{B7FA188F-EBE3-11D0-87FE-080009EC732A}";

        ICommandItem cmdItem = documentBars.Find(cmdID, false, false);

        app.CurrentTool = cmdItem;


        } catch (exception myException)


              messageBox.Show("Error: " + myException);


} }



I am working with map documents, so I may be using the wrong Arc Objects, but again, when I click my button, I get an error:

System.NullReferenceException: Object not set to an instance of an abject. So something is still null or not getting set. More tracing perhaps, but I am wondering if I am even going about this the right way. Any help on this would be greatly appreciated. Thanks in advance.