<?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: Creating *actual* custom commands with BaseToolbar in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/creating-actual-custom-commands-with-basetoolbar/m-p/183074#M4751</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Kevin, hopefully this isn't too little too late for you, but here's what you actually need to do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Go back to using the standard add-in toolbar setup. (Unless there's some other reason to create your own that you didn't mention. This will still work with that as well, it's just easier to work with the Config.esriaddinx setup than defining custom classes, IMHO.) Then add a Menu to the Toolbar. Then add a new Add-in Component and select Multi-Item. Fill in the details about your Multi-Item (it doesn't really make much difference as far as I've been able to tell what you put there, but just in case...) and then add it to your Menu.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Finally, open the .cs/.vb file and you'll need to override two methods: (the project that I used this method on was written in VB.Net, so I'll just use that for my examples even though I've grown more fond of C#...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Protected Overrides Sub OnPopup(ByVal items As ESRI.ArcGIS.Desktop.AddIns.MultiItem.ItemCollection)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;and&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Protected Overrides Sub OnClick(ByVal item As ESRI.ArcGIS.Desktop.AddIns.MultiItem.Item)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;OnPopup happens when your Menu is opened and what it's expecting you to do is add Items to the ItemCollection that is passed in. The Item class is very simple and provides things similar to a Command. But you don't need to subclass it and you probably don't need to worry about setting anything other than the Caption. In my code, I have each of my possible Items defined as private members and I just add the ones I need, depending on certain conditions, in the call to OnPopup. Then in the OnClick call, I check to see which one of my Items was returned to me as the one that was clicked and do whatever needs to be done based on that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In your case, it sounds like the Items are essentially populated using your file structure. In that case, you might want to have some other piece of information in addition to the Caption, like the full path as opposed to a more friendly version of the file name. So let me give a quick example of what you could do:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Protected Overrides Sub OnPopup(ByVal items As ItemCollection)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim files As List(Of System.IO.FileInfo) = 'Some method that returns a collection of FileInfo objects in the desired path(s)
&amp;nbsp;&amp;nbsp;&amp;nbsp; For Each file In files
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; items.Add(New Item With {.Caption = file.Name, .Tag = file.FullName})
&amp;nbsp;&amp;nbsp;&amp;nbsp; Next
End Sub

Protected Overrides Sub OnClick(ByVal item As Item)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim file As New System.IO.FileInfo(item.Tag)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Code to open the file and do something with it
End Sub
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The possibilities of what you want to do with it from there are nearly endless. You can then have as many or as few items show up as you want (I think), but I would suggest you do something to keep it from being several hundred items all at once... &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps you and/or someone else! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 09:19:25 GMT</pubDate>
    <dc:creator>RobertMaddox</dc:creator>
    <dc:date>2021-12-11T09:19:25Z</dc:date>
    <item>
      <title>Creating *actual* custom commands with BaseToolbar</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/creating-actual-custom-commands-with-basetoolbar/m-p/183071#M4748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am in the process of creating a toolbar containing nested menus with buttons and other menus for access of some custom functionality for end users.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For whatever reason, since the ArcMap addin templates do not seem to allow a toolbar contained menus with nested submenus, I turned to the non-addin approach of creating a BaseToolbar which has the ability to add commands (menus, buttons, etc.):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
public MyToolbar()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.AddItem(typeof(ButtonItem));
}
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;where ButtonItem is a class which inherits BaseCommand:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
[Guid("2b3041ff-482c-4c36-aef3-2bf79546fb82")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("TestLib.ButtonItem")]
public class ButtonItem : BaseCommand
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // ...
}
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I really want these buttons to do is have some non-ESRI functionality (which none of the examples provide), for example, when clicked, retrieves some id, name, or caption of this button, and traverses a directory on the file system to add a new layer to the map, or create a config .xml file somewhere on the file system.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, there seems to be no room to add any custom methods or properties to ButtonItem, since the method AddItem() of the base toolbar does not take an instantiated object, but either a progid, or class type.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I handle the onClick method of this specific button to access class properties?&amp;nbsp; There does not seem to be a clear indication of how/when the constructor and onCreate methods are executed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone have experience utilizing this toolbar/menu style, or know how to dynamically add nested menu items to an add-in toolbar (loop over a directory, and add a menu item for a folder, or a button item for a file)?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jun 2014 12:06:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/creating-actual-custom-commands-with-basetoolbar/m-p/183071#M4748</guid>
      <dc:creator>KevinYanuk</dc:creator>
      <dc:date>2014-06-09T12:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating *actual* custom commands with BaseToolbar</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/creating-actual-custom-commands-with-basetoolbar/m-p/183072#M4749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I guess I'm not following your definition of the problem.&amp;nbsp; A custom command can do whatever you want it to do.&amp;nbsp; Just add whatever code you need to the OnClick event.&amp;nbsp; When the command is clicked, that code executes.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jun 2014 14:19:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/creating-actual-custom-commands-with-basetoolbar/m-p/183072#M4749</guid>
      <dc:creator>NeilClemmons</dc:creator>
      <dc:date>2014-06-16T14:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating *actual* custom commands with BaseToolbar</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/creating-actual-custom-commands-with-basetoolbar/m-p/183073#M4750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Kevin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Instead of deriving your custom toolbar from &lt;/SPAN&gt;&lt;STRONG&gt;BaseToolbar&lt;/STRONG&gt;&lt;SPAN&gt; in the &lt;/SPAN&gt;&lt;STRONG&gt;ESRI.ArcGIS.ADF&lt;/STRONG&gt;&lt;SPAN&gt; namespace, have you considered implementing the &lt;/SPAN&gt;&lt;STRONG&gt;&lt;A href="http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//002300000065000000"&gt;ICommandBar&lt;/A&gt;&lt;/STRONG&gt;&lt;SPAN&gt; interface?&amp;nbsp; Any custom tools/buttons/menus you want to add to it would need to implement the &lt;/SPAN&gt;&lt;STRONG&gt;&lt;A href="http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//00430000001s000000"&gt;ICommand&lt;/A&gt;&lt;/STRONG&gt;&lt;SPAN&gt; interface.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regarding the OnCreate event, the help documentation for ICommand says this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Commands are constructed once initially to get information about them, like the name, bitmap, etc and then they are destroyed.&amp;nbsp; When the final, complete construction takes place, the OnCreate method gets called.&amp;nbsp; OnCreate gets called only once, so you can rely on it to perform initialization of member variables.&amp;nbsp; You can check for initialized member variables in the class destructor to find out if OnCreate has been called previously.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regarding "nested menus," the &lt;/SPAN&gt;&lt;STRONG&gt;&lt;A href="http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//00430000006z000000"&gt;IToolPalette&lt;/A&gt;&lt;/STRONG&gt;&lt;SPAN&gt; may be what you're looking for.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jun 2014 18:42:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/creating-actual-custom-commands-with-basetoolbar/m-p/183073#M4750</guid>
      <dc:creator>ErinBrimhall</dc:creator>
      <dc:date>2014-06-16T18:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating *actual* custom commands with BaseToolbar</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/creating-actual-custom-commands-with-basetoolbar/m-p/183074#M4751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Kevin, hopefully this isn't too little too late for you, but here's what you actually need to do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Go back to using the standard add-in toolbar setup. (Unless there's some other reason to create your own that you didn't mention. This will still work with that as well, it's just easier to work with the Config.esriaddinx setup than defining custom classes, IMHO.) Then add a Menu to the Toolbar. Then add a new Add-in Component and select Multi-Item. Fill in the details about your Multi-Item (it doesn't really make much difference as far as I've been able to tell what you put there, but just in case...) and then add it to your Menu.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Finally, open the .cs/.vb file and you'll need to override two methods: (the project that I used this method on was written in VB.Net, so I'll just use that for my examples even though I've grown more fond of C#...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Protected Overrides Sub OnPopup(ByVal items As ESRI.ArcGIS.Desktop.AddIns.MultiItem.ItemCollection)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;and&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Protected Overrides Sub OnClick(ByVal item As ESRI.ArcGIS.Desktop.AddIns.MultiItem.Item)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;OnPopup happens when your Menu is opened and what it's expecting you to do is add Items to the ItemCollection that is passed in. The Item class is very simple and provides things similar to a Command. But you don't need to subclass it and you probably don't need to worry about setting anything other than the Caption. In my code, I have each of my possible Items defined as private members and I just add the ones I need, depending on certain conditions, in the call to OnPopup. Then in the OnClick call, I check to see which one of my Items was returned to me as the one that was clicked and do whatever needs to be done based on that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In your case, it sounds like the Items are essentially populated using your file structure. In that case, you might want to have some other piece of information in addition to the Caption, like the full path as opposed to a more friendly version of the file name. So let me give a quick example of what you could do:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Protected Overrides Sub OnPopup(ByVal items As ItemCollection)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim files As List(Of System.IO.FileInfo) = 'Some method that returns a collection of FileInfo objects in the desired path(s)
&amp;nbsp;&amp;nbsp;&amp;nbsp; For Each file In files
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; items.Add(New Item With {.Caption = file.Name, .Tag = file.FullName})
&amp;nbsp;&amp;nbsp;&amp;nbsp; Next
End Sub

Protected Overrides Sub OnClick(ByVal item As Item)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim file As New System.IO.FileInfo(item.Tag)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Code to open the file and do something with it
End Sub
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The possibilities of what you want to do with it from there are nearly endless. You can then have as many or as few items show up as you want (I think), but I would suggest you do something to keep it from being several hundred items all at once... &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps you and/or someone else! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:19:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/creating-actual-custom-commands-with-basetoolbar/m-p/183074#M4751</guid>
      <dc:creator>RobertMaddox</dc:creator>
      <dc:date>2021-12-11T09:19:25Z</dc:date>
    </item>
  </channel>
</rss>

