Productivity Tips

Add Custom Commands and Tools to ArcGIS

By Jorge Ruiz-Valdepeña, ESRI Education Services

As part of the evolution of ESRI products, users name and create a small gray box on the user Executable file (.exe) . Add custom commands tell ESRI what additional functionality they want interface. Add commands to the new developed for ArcMap or ArcCatalog using the in the next release of the software. In the past, using the Commands of the Customize following procedure: clients could purchase ESRI object code and dialog box. 1. Choose Tools > Customize from the standard develop specific functionality, but this was not an toolbar. affordable option for everyone. With the adoption Commands 2. In the Customize dialog box on the of object-oriented architecture, users are now The Commands tab on the Customize dialog Commands tab, click Add From File. able to use any COM-compliant programming box contains all existing ArcMap or ArcCatalog 3. Navigate to the file containing the custom language to modify ESRI software. commands. Select a particular command and drag command, click the desired file, and click Open. However, before writing any code, determine it from the Customize dialog box onto a toolbar The Added Objects dialog box appears. It reports if the functionality you need has not already as a or onto a as a menu choice. the new objects that have been registered with been developed. ArcGIS Desktop, through its Set a location for saving these customizations— ArcMap or ArcCatalog. Click OK. applications ArcMap and ArcCatalog, provides either save customizations in the current map 4. Click the tab. Click the Commands a handful of very useful general functions document (.mxd), or in the Normal template tab. Click the custom commands category in the accessible through the graphic user interface. (.mxt). Choosing the current .mxd makes the Categories list. A good place to start is by using the Customize customizations available only for that particular Click and drag the command from the dialog box to access existing tools and commands document. Saving customizations to the Normal Commands list and drop it on the target toolbar. that are not available with the default interface template makes the customizations available Click Close. Using Add From File causes the and by using samples that supply extensions, every time a new document is created. system to automatically register the component tasks, views, and renderer folders. Additional DLL. Note that this method cannot be used for resources can be found within the Developers Options DLLs created with Visual Studio .NET. Help system for the ArcGIS Desktop software The Options tab on the Customize dialog box developer kit, the ESRI Developer Network Web controls basic properties of the customization About Adding Custom site (end/esri.com), and the documentation that development environment. Commands Using Samples comes with ArcGIS. All ArcMap or ArcCatalog commands, Install the samples folder during the software organized by category, are available through the installation process by selecting the Complete The Customize Dialog Box Commands tab. By highlighting a category on option. This option will install the Developers ArcMap and ArcCatalog can be customized the left side of the dialog box, all commands in Help Kit and all samples. Some of the sample without writing a single line of code. Create, add, that category are listed on the right side of the custom commands can be accessed via Add move, and remove toolbars and commands, and dialog box. Some familiar command categories From File as mentioned above, while others even add tools that others have created using the include Selection, Pan/Zoom, and File. require the Components Categories application. Customize dialog box. To activate the Customize Many of these commands are not included dialog box, choose Tools > Customize on the with the default ArcGIS interface. Add a Adding Samples standard menu. The Customize dialog box has command to the interface by selecting it in the as a Component Category Toolbars, Commands, and Options tabs. The dialog box and dragging it to a toolbar as a After compiling the sample and creating a new Toolbars and Commands tabs are used to modify button or a menu as a menu choice. Note that DLL using the sample source code project file, the user interface, while the Options tab provides controls that require user interaction will not register the DLL using Regsvr32. control over basic customization settings. work as menu choices, and some commands, 1. From the , choose Start > Run. such as layer properties, only work as context 2. In the Run dialog box, type “regsvr32 ” (for example, type “regsvr32 With the Toolbars tab of the Customize dialog available with ArcGIS Desktop, choose ArcGIS D:\Samples\ApplicationFramework\Sample box, existing toolbars can be turned off and on, Desktop Help > Customizing from the main Extension\SampleExtension.dll”). renamed, or deleted. Any changes can be undone menu. 3. Click OK. by resetting an individual toolbar to its original After the DLL has been registered, use the state by choosing Reset in the Customize Adding Custom Commands Component Category Manager utility to add dialog box. by Adding from a File the sample DLL to the appropriate component Also, use the Toolbars tab to create brand Custom commands are functions created with category. There are several ways to launch the new toolbars. When creating a new toolbar, any COM-compliant programming language Component Category Manager. One way is to the system will prompt for the new toolbar’s that can be distributed as an ActiveX DLL or navigate to the directory where ArcGIS was

58 ArcUser October–December 2006 www.esri.com Hands On

For more samples, browse the contents of the Developing_with_ArcObjects/ Desktop_Development_Guide.pdf

installed and run Categories.exe (for example, implementing custom commands by browsing the C:\Program Files\ArcGIS\bin\categories.exe). sample code embedded within the contents of the Another method is to click Start > All Programs Developing_with_ArcObjects/Desktop_ Select a > ArcGIS > Developer Tools > Component Development_Guide.pdf, part particular Category Manager. of the documentation command and Once the sample is added to the appropriate that comes with drag it from the Commands tab component category, ArcGIS will be ArcGIS. in the Customize automatically notified of the new objects. If the dialog box to object is not recognized, shut down the computer a toolbar as a and restart it and reopen ArcGIS. button or onto a 1. In the Component Category menu as a menu Manager, double-click the category choice. where the sample will be registered. Click Add Object. 2. In the Find Add-in dialog box, navigate to the component file, select it, and click Open. 3. In the Add Object dialog box, check the sample to add to this component category and click OK. 4. The Component Category Manager now lists the sample in the component. Click OK.

For More Information Get more information about creating and

The

Customize dialog box has three tabs— Toolbars, Commands, and Options. The Options tab sets the development environment. Use the Component Category Manager utility to add the sample DLL to the appropriate component category. www.esri.com ArcUser October–December 2006 55