Python Add-Ins – How to add built-in commands to your custom toolbar or menu

This blog shows how you can add existing built-in commands to your existing custom toolbar or menu.

ArcGIS 10.1 introduced Python to the list of languages for creating desktop add-ins. To get started with Python add-ins or to learn more about customizing and extending desktop for ArcGIS with Python add-ins, check out the guide book available with the ArcGIS 10.1 desktop help.

If you already have a python add-in, you can easily add existing built-in commands to your custom toolbar or menu in three steps:

  1. Look up the command you want to add. The following links list the commands for each desktop application:
    ArcMap commands
    ArcCatalog commands
    ArcScene commands
    ArcGlobe commands  

    Once, you have found the command you want to add, copy the ProgID (as illustrated below).

  2. Navigate to the folder where your add-in project is located and edit the config.xml file. Within the <Items> </Items> tags, add the following line and save and close the file.
    <Button refID=”esriArcMapUI.ZoomToSelectedCommand”/> 

  3. Rebuild and test your add-in. The following button will be available on your toolbar:  When you select some features, the button is enabled and when clicked, the map will zoom to the selected features. If no features are selected, the button is disabled.

To add an existing tool command to a toolbar, follow the same steps as above. Instead of Button refID, use Tool refID:

Finally, here is an example of a built-in button command added to a custom menu. Note tools cannot exist on menus.

This entry was posted in Developer, Python and tagged , , . Bookmark the permalink.

Leave a Reply

9 Comments

  1. offermann says:

    I can see no “Tool rfID” in the screenshot of the last example. Seems the last screenshot is a wrong graphic, showing a menu with buttons instead of a toolbar with tool commands.

  2. jpardy84 says:

    Hi offermann, thank-you for this find. I just updated the post.

  3. curtvprice says:

    Neat! Is there a way to find GUIDs for commands not listed in the table? I was looking for the Buffer Wizard and it isn’t there.

  4. khillstrom says:

    I have a followup question about subtypes to the ProgID. How do you reference them in your config.xml? It seems like without them the tool is disabled.

    Thanks,

    Karl

  5. johnmdye says:

    So, I was tried using the refID for a button, but I wanted to define a different image and did so in the Config.xml, but it seems that was overridden because it still used the standard button image for the control.

  6. johnmdye says:

    Taking a second look, it seems it overrides everything specified for a button in the addin, including the Tooltip, and Message. It makes me wonder what the point of this is when I could just create a new toolbar in ArcMap, drag any native commands I want onto said toolbar, customize the images, change the tooltips, save customizations to the MXD and distribute the MXD.