<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Accessing/Using ArcMaps Commands via C# in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/accessing-using-arcmaps-commands-via-c/m-p/679977#M18265</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After hours and hours of research, I think I found a solution to my specific problem. I wanted to post an explanation and solution to what I had come up with, just in case anyone else ever has the same issue. Here goes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I wanted to capture one of ArcMaps tools/items from their toolbar. I wanted to capture the "Select Element" tool (the arrow). I first needed to get the GUID of the tool that I wanted to capture. Once I had the GUID, I would need to find it on ArcMaps toolbar and then access it/highlight it/show it, etc. The correct word would be Activate. For my simple test, I had a button that when clicked, it would select the "Select Element" tool. Code below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c#" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14164338385064174 jive_text_macro" jivemacro_uid="_14164338385064174" modifiedtitle="true"&gt;
&lt;P&gt;UID myUid = new UID();&lt;/P&gt;
&lt;P&gt;myUid.Value = "esriArcMapUI.SelectTool";&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;IDocument ThisDoc = ArcMap.Application.Document;&lt;/P&gt;
&lt;P&gt;ICommandBars CommandBars = ThisDoc.CommandBars as ICommandBars;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;CommandBars.Find(myUid);&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;ICommandItem myItem = CommandBars.Find(myUid) as ICommandItem;&lt;/P&gt;
&lt;P&gt;myItem.Execute();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 19 Nov 2014 21:52:19 GMT</pubDate>
    <dc:creator>JamariPowers</dc:creator>
    <dc:date>2014-11-19T21:52:19Z</dc:date>
    <item>
      <title>Accessing/Using ArcMaps Commands via C#</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/accessing-using-arcmaps-commands-via-c/m-p/679976#M18264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Namespace MYPROJECT&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; public class myButton : Button&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IApplication app;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public myButton()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;protected override void onClick()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;try&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ICommandBars documentBars = app.Document.CommandBars;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UID cmdID = new UIDClass();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmdID.Value = "{B7FA188F-EBE3-11D0-87FE-080009EC732A}";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ICommandItem cmdItem = documentBars.Find(cmdID, false, false);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; app.CurrentTool = cmdItem;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } catch (exception myException)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; messageBox.Show("Error: " + myException);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt; } } &lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Nov 2014 00:45:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/accessing-using-arcmaps-commands-via-c/m-p/679976#M18264</guid>
      <dc:creator>JamariPowers</dc:creator>
      <dc:date>2014-11-19T00:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing/Using ArcMaps Commands via C#</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/accessing-using-arcmaps-commands-via-c/m-p/679977#M18265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After hours and hours of research, I think I found a solution to my specific problem. I wanted to post an explanation and solution to what I had come up with, just in case anyone else ever has the same issue. Here goes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I wanted to capture one of ArcMaps tools/items from their toolbar. I wanted to capture the "Select Element" tool (the arrow). I first needed to get the GUID of the tool that I wanted to capture. Once I had the GUID, I would need to find it on ArcMaps toolbar and then access it/highlight it/show it, etc. The correct word would be Activate. For my simple test, I had a button that when clicked, it would select the "Select Element" tool. Code below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c#" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14164338385064174 jive_text_macro" jivemacro_uid="_14164338385064174" modifiedtitle="true"&gt;
&lt;P&gt;UID myUid = new UID();&lt;/P&gt;
&lt;P&gt;myUid.Value = "esriArcMapUI.SelectTool";&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;IDocument ThisDoc = ArcMap.Application.Document;&lt;/P&gt;
&lt;P&gt;ICommandBars CommandBars = ThisDoc.CommandBars as ICommandBars;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;CommandBars.Find(myUid);&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;ICommandItem myItem = CommandBars.Find(myUid) as ICommandItem;&lt;/P&gt;
&lt;P&gt;myItem.Execute();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Nov 2014 21:52:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/accessing-using-arcmaps-commands-via-c/m-p/679977#M18265</guid>
      <dc:creator>JamariPowers</dc:creator>
      <dc:date>2014-11-19T21:52:19Z</dc:date>
    </item>
  </channel>
</rss>

