AutoCAD toolbar customization the right way

Or: "The Toolbars dialog is for wimps!"

by Mark Middlebrook, www.markcad.com.


Note: I updated this article on 28-Nov-2000 to respond to several readers' comments. The changes include a clarification of MNU versus MNS files. I futher updated it on 03-Apr-2002 to mention the possibility of compiling BMP files into a single DLL file.

In AutoCAD 2002 through R13, you can modify or add toolbars by choosing the Customize button in the Toolbars dialog box. (Enter the TOOLBAR command, or simply right click on any toolbar icon. In AutoCAD 2002-2000, choose Customize from the right click menu). If you've ever tried to customize toolbars in this way, though, you've probably run into problems such as:

Because of all the potential problems, it's usually better to dispense with the Toolbars dialog box for customization -- especially if you care enough about your custom toolbars to want to preserve them or copy them to other computers. (You still can the Toolbars dialog for turning individual toolbars on and off or switching between small and large button bitmaps).

The better way to customize toolbars is to edit the menu source file (MNU or MNS file) directly with a text editor such as Notepad and create any custom button bitmaps with a paint program such as Microsoft Paint. This approach requires modest familiarity with AutoCAD menu customization, but it ensures reliable results. In addition, it gives you bragging rights over all of the wimps who are struggling to create custom toolbars with the Toolbars dialog box.

The procedure later in this article demonstrates how to create a custom toolbar in AutoCAD R14 with Notepad and Paint, both of which come with Windows. (The procedure also works for AutoCAD 2002-2000.) We'll store the custom toolbar in a partial menu file, which is good practice for all of your custom menu components, toolbar or otherwise.

Which menu file do I edit?

Although you can edit and add to the toolbars in the standard AutoCAD menu (Acad.Mnu and Acad.Mns), your life will be easier if you don't. I recommend that you create a completely separate custom menu file for your custom toolbars and any other custom menu components. (See my CADALYST magazine article Elegant AutoCAD customization eliminates problems for more information.)

I also recommend that you create your custom menu in an MNS file, rather than in an MNU file. The AutoCAD menu customization tips page unravels the menu file mess and explains why you should eschew MNU files.

Step-by-step procedure

This procedure doesn't address every nuance of toolbar customization, but it will take you quickly through all of the steps, as shown in the figure. For more information about menu customization in general and toolbar customization in particular, refer to chapter 4 of the AutoCAD Customization Guide (available in the on-line help system and, for an additional cost, in hardcopy).

  1. Create a custom support file directory, if you don't already have one.

    See Options, Files in AutoCAD 2002-2000 or Preferences, Files in AutoCAD R14 for a list of directories in your support file search path. Although you can keep custom support files in an AutoCAD directory such as C:\Program Files\AutoCAD 2002\Support, it's preferable to create a separate custom support directory (e.g., C:\A2k2Cust), add it to the support file search path, and store your custom support files there.

  2. Start Notepad and create a new file called MyCustom.Mns in your custom support directory (or any other directory on your AutoCAD support file search path.)

    Note that we're not creating an MNU file. Since R13, AutoCAD doesn't need the MNU file, and working only with an MNS file eliminates the possibility of losing MNS file changes.

  3. Create a menu group name, ***TOOLBARS menu section, and one toolbar definition by typing the following lines into MyCustom.Mns:

    ***MENUGROUP=MYCUSTOM
    ***TOOLBARS
    **MyTB_Favorites
    [_Toolbar("My Favorites", _Left, _Show, 2, 0, 1)]
    
  4. Copy stock AutoCAD toolbar buttons from Acad.Mns.

    For each toolbar button that you want to copy from a stock AutoCAD toolbar, locate the corresponding line in Acad.Mns and copy everything from the opening bracket to the end of the line to MyCustom.Mns. For example these two lines add the Object Snap Settings and Zoom Extents buttons from the AutoCAD R14 Standard toolbar flyouts:

    [_Button("Object Snap Settings", "ICON_16_OSNAP", "ICON_24_OSNAP")]'_osnap
    [_Button("Zoom Extents", "ICON_16_ZOOEXT", "ICON_24_ZOOEXT")]'_zoom _e
    

    In order to locate a line in Acad.Mns corresponding to a particular toolbar button, point at the button in AutoCAD and wait for the ToolTip to pop up. Then open Acad.Mns (located in the AutoCAD Support directory) in Notepad and search for the ToolTip text.

    The bitmaps for all stock AutoCAD toolbar buttons (e.g., "ICON_16_OSNAP" and "ICON_24_OSNAP" in the Object Snap Settings line above) are stored in AcadBtn.Dll, which is located in the AutoCAD program directory. See the next step for more information about bitmap differences between AutoCAD R14 and AutoCAD 2000+ (i.e., 2000, 2000i, and 2002).

  5. Create custom toolbar button bitmaps and add button definitions to MyCustom.Mns.

    For each custom toolbar button that you want to create (i.e., buttons that don't appear in any of the stock AutoCAD toolbars), you must perform two steps: create the button bitmaps and add a button definition line to the menu file.

    First, in Microsoft Paint create a 16x15 pixel BMP file. To specify the size of a BMP file in Paint, choose Image, Attributes. Then draw the image using Paint's drawing tools (if you're unfamiliar with Paint, use its on-line help). You'll probably want to use a gray background to match AutoCAD's other icons. Save the files in the same directory with MyCustom.Mns.

    If you're creating toolbars for AutoCAD R14, you need to create a second, large version (24x22 pixels) of each bitmap in a separate BMP file. AutoCAD R14 displays the large version when you turn on Large Buttons in the Toolbars dialog. AutoCAD 2000+ uses only the small 16x15 bitmap, and stretches the image out when you turn on Large Buttons (the results are pretty ugly, but the use of a single bitmap does make your customization job easier!).

    Second, add a line to MyCustom.Mns in the following format, substituting appropriate values for the parameters in italics:

    [_Button("tool_tip", "16_pixel.Bmp", "24_pixel.Bmp")]menu_macro
    

    In AutoCAD 2000+, you specify the same BMP file name twice:

    [_Button("tool_tip", "16_pixel.Bmp", "16_pixel.Bmp")]menu_macro
    

    For example, suppose you want to create a custom button for BREAK @ (breaking an object into two without deleting any part of it). Create BrkAt16.Bmp in Paint (and BrkAt24.Bmp if you're using AutoCAD R14), then add the following line to MyCustom.Mns:

    [_Button("Break @", "BrkAt16.Bmp", "BrkAt24.Bmp")]_.BREAK \@
    

    The menu_macro string (_.BREAK \@ in this example) uses AutoCAD's menu macro syntax - see chapter 4 of the AutoCAD Customization Guide for details.

  6. Save MyCustom.Mns and load it with the MENULOAD command.

    Because MyCustom.Mns is a partial menu, you attach it with the MENULOAD command:

    1. Enter MENULOAD at the AutoCAD command prompt.
    2. Use the Browse button to locate MyCustom.Mns.
    3. Choose the Load button.
    4. Choose Close.

    AutoCAD automatically displays your custom toolbar (in the figure below, it's the toolbar with three buttons just to the right of the Modify toolbar - of course you can drag it to a different location).

    AutoCAD R14 retains the attachment status of partial menus and the layout information for any toolbars in the partial menus, so normally you only have to perform this step once.

  7. Test each button and look for missing bitmaps.

    Pick each button in turn to make sure that it runs the right macro. Use the Toolbars dialog to toggle between large and small buttons, making sure that you don't see any smiley faces in place of bitmaps.

  8. Install the custom menu on other users' computers.

    Create the custom support directory and add it to the AutoCAD support file search path, as described in step 1. Then copy the MyCustom.* and *.Bmp files to the custom support directory. Finally, partially load the menu file in AutoCAD, as described in step 6. If you plan to revise your office's custom toolbars frequently, you might want to keep them on a commonly available network directory and partially load them from there.

Tips

Return to www.markcad.com.


Original article 25-Feb-2000; last updated 20-Jan-2004 by
mark@markcad.com