<?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: Execute a command programmatically in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357092#M9438</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I have developed a command that implements ICommand and ITool. This command is registered in the ESRI MX Commands category. How can I execute this command programmatically without having to add it to a toolbar or a commandbar?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Not totally sure you can do this, but if it's registered already then you should be able to execute it via it's GUID just like any other registered command.&amp;nbsp; For example, this code would initiate the Sketch Tool:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'set the current tool to be the editor Sketch tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pUID As New ESRI.ArcGIS.esriSystem.UID&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pUID.value = "esriCore.SketchTool"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pCommandItem = m_pApp.Document.CommandBars.Find(pUID)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_pApp.CurrentTool = pCommandItem&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_pEditEvents = pEditor&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 28 Feb 2011 13:27:23 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2011-02-28T13:27:23Z</dc:date>
    <item>
      <title>Execute a command programmatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357091#M9437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have developed a command that implements ICommand and ITool. This command is registered in the ESRI MX Commands category. How can I execute this command programmatically without having to add it to a toolbar or a commandbar?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Feb 2011 21:14:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357091#M9437</guid>
      <dc:creator>GagagDa_Morvi</dc:creator>
      <dc:date>2011-02-24T21:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Execute a command programmatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357092#M9438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I have developed a command that implements ICommand and ITool. This command is registered in the ESRI MX Commands category. How can I execute this command programmatically without having to add it to a toolbar or a commandbar?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Not totally sure you can do this, but if it's registered already then you should be able to execute it via it's GUID just like any other registered command.&amp;nbsp; For example, this code would initiate the Sketch Tool:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'set the current tool to be the editor Sketch tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pUID As New ESRI.ArcGIS.esriSystem.UID&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pUID.value = "esriCore.SketchTool"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pCommandItem = m_pApp.Document.CommandBars.Find(pUID)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_pApp.CurrentTool = pCommandItem&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_pEditEvents = pEditor&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Feb 2011 13:27:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357092#M9438</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2011-02-28T13:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Execute a command programmatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357093#M9439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Not totally sure you can do this, but if it's registered already then you should be able to execute it via it's GUID just like any other registered command.&amp;nbsp; For example, this code would initiate the Sketch Tool:&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'set the current tool to be the editor Sketch tool&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pCommandItem As ESRI.ArcGIS.Framework.ICommandItem&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pUID As New ESRI.ArcGIS.esriSystem.UID&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pUID.value = "esriCore.SketchTool"&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pCommandItem = m_pApp.Document.CommandBars.Find(pUID)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_pApp.CurrentTool = pCommandItem&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_pEditEvents = pEditor&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, I will give it a try, all online examples show this technique. But would it work even if the command has not been added to the CommandBar - because the example tries to find the command by ICommandBars.Find().&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Feb 2011 13:33:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357093#M9439</guid>
      <dc:creator>GagagDa_Morvi</dc:creator>
      <dc:date>2011-02-28T13:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Execute a command programmatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357094#M9440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks, I will give it a try, all online examples show this technique. But would it work even if the command has not been added to the CommandBar - because the example tries to find the command by ICommandBars.Find().&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;oooh not sure.&amp;nbsp; I've always implemented an IToolBarDef class, so I am unsure of success in doing what you are attempting.&amp;nbsp; Hopefully someone who has experienced this can jump in and explain.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Feb 2011 13:59:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357094#M9440</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2011-02-28T13:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Execute a command programmatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357095#M9441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This code uses the tool's ProgId:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pUID.value = "esriCore.SketchTool"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It has been my experience that using the ProgId requires the command or tool to be on a toolbar or menu somewhere.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you use the actual class GUID, then the command or tool does not have to be on a toolbar or menu:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pUID.value = "{" &amp;amp; yourClass.ClassId &amp;amp; "}"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code above is .NET and assumes the command/tool class is in your code project.&amp;nbsp; You can also just use the hard-coded GUID (you'll have to do this for built-in tools and tools whose code is not in your project).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Mar 2011 13:06:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357095#M9441</guid>
      <dc:creator>NeilClemmons</dc:creator>
      <dc:date>2011-03-01T13:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Execute a command programmatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357096#M9442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;This code uses the tool's ProgId:&lt;BR /&gt;pUID.value = "esriCore.SketchTool"&lt;BR /&gt;&lt;BR /&gt;It has been my experience that using the ProgId requires the command or tool to be on a toolbar or menu somewhere.&lt;BR /&gt;&lt;BR /&gt;If you use the actual class GUID, then the command or tool does not have to be on a toolbar or menu:&lt;BR /&gt;pUID.value = "{" &amp;amp; yourClass.ClassId &amp;amp; "}"&lt;BR /&gt;&lt;BR /&gt;The code above is .NET and assumes the command/tool class is in your code project.&amp;nbsp; You can also just use the hard-coded GUID (you'll have to do this for built-in tools and tools whose code is not in your project).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; Thanks Neil, I will give it a try and report.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2011 02:33:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357096#M9442</guid>
      <dc:creator>GagagDa_Morvi</dc:creator>
      <dc:date>2011-03-04T02:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: Execute a command programmatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357097#M9443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks Neil, I will give it a try and report.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; Thank you , Neil. It has worked as per your suggestion.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2011 14:08:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/execute-a-command-programmatically/m-p/357097#M9443</guid>
      <dc:creator>GagagDa_Morvi</dc:creator>
      <dc:date>2011-03-04T14:08:57Z</dc:date>
    </item>
  </channel>
</rss>

