2. AutoCAD's Toolbar Macros

by Ralph Grabowski

In my opinion, the easiest part of AutoCAD to customize is the toolbar found in AutoCAD, starting with the Windows version of Release 11 (yes, there was a version of R11 for Windows called the "AutoCAD Windows Extension," or AWE for short.)

This tutorial is based on the toolbars found in Release 11, Release 12, and the first two releases of LT.
Release 13's toolbar is significantly different.

The toolbar gives you single-click access to almost any command or group of commands. Instead of hunting through AutoCAD's maze of menus -- is the Hatch command under Draw or Construct? -- or trying to recall the exact syntax of a typed command -- was that "Viewpoint" or "Vpoint"? -- the toolbar lets you collect your most-used commands in a single, convenient strip across the top of the drawing.

A group of commands executed by a single keystroke or mouse click is called a "macro." Figuring in the time it takes to write and debug the macro, my rule-of-thumb is to write a macro any time the same action is repeated more than three times.

Before looking at how AutoCAD lets you customize its toolbar buttons, let's try using them:

  1. Start AutoCAD for Windows, either Release 11, 12, or LT.
  2. When AutoCAD appears, there are three rows above the drawing area. From top to bottom, these are (1) the title bar; (2) the menu bar; and (3) the toolbar.
  3. The toolbar replaces the status line of DOS-based AutoCAD. From left to right, it displays:
  4. Move the cursor over any toolbar button and press the mouse's right button. For example, when you click on the first of these buttons (the icon looks like a six-pane window), AutoCAD moves the location of the toolbox. Each time you click on the button, AutoCAD executes the Toolbox command, which moves the toolbox from stuck to the side, to floating, to invisible.

Looking Inside a Toolbar Macro

Now that we've seen how the toolbar works, let's dive right in and look at how AutoCAD customizes that row of buttons on the toolbar.

  1. If you haven't already, start AutoCAD for Windows.
  2. Move the cursor up to the toolbar, then over any of the square buttons to the right of the coordinate display (see figure).
  3. Click the mouse's right mouse button.
  4. The right-click action brings up a dialogue box. Named Toolbar Button Customization, this single dialogue box controls every aspect of the toolbar (well, almost: next month we'll see how you can bypass the dialogue box). Let's look at the dialogue box in detail:

Title Bar: At the top, the dialogue box's title lists the button number being customized. In the figure, we are looking at the dialogue box for Button 1.

AutoCAD LT Command: At the bottom of the dialogue is the macro attached to the toolbar button. When you click on the toolbar button, AutoCAD executes the "macro string" typed here. The macro string "\3\3_TOOLBOX" consists of three control characters and one AutoCAD command with the following meaning: \3 This control character imitates pressing [Ctrl]+C at the keyboard, which cancels the command currently in progress. The backslash "\" alerts AutoCAD that this is a control character and not a regular AutoCAD command. The number "3" comes from C being the third letter of the alphabet. AutoCAD recognizes 12 control characters (Autodesk forgot to document those marked *):

        Character       Meaning
        ---------------------------------------------------------------------------------------
        \2      Toggle snap mode between on and off, like [Ctrl]+B
        \3      Cancel current command, like [Ctrl]+C
        \4      Change coordinate display mode, like [Ctrl]+D
        \5      Switch to next isometric plane, like [Ctrl]+E
        \7      Toggle grid display, like [Ctrl]+G
        \8      * Backspace, like [Ctrl]+H
        \15     * Toggle ortho mode, like [Ctrl]+O
        \22     * Switch to next viewport, like [Ctrl]+V
        \n      Starts a new line
        \t      * Tab; has same effect as space
        \nnn    * Use ASCII character nnn
        \\      Allows use of the \ character
        ----------------------------------------------------------------------------------------

\3\3 Most macros should start with at least two \3 since many AutoCAD commands are two levels deep. I recommend starting macros with \3\3\3 since some commands, like PEdit, are three levels deep. If the command is transparent (starts with the ' apostrophe), then you don't prefix the macro with the Cancel character.

_ The underscore is an AutoCAD convention that "internationalizes" the command. Whether you are using the German, Spanish, or Japanese version of AutoCAD, prefixing the command name with the underscore ensures the English-language version of the command will always work.

TOOLBOX Finally, we arrive at the command name! In macros, you type AutoCAD commands and their options exactly the way you would type them on the keyboard at the Command: prompt.

(Space) It is barely visible in the figure, but there is a space after TOOLBOX. The space is the equivalent of pressing the [Enter] or [Spacebar] keys. AutoCAD automatically adds the space since every command is executed by pressing the [Enter] key. When you need to suppress the automatic space, add a ; semi-colon.

Tip

Here is how to add a pause to toolbar marco, thanks to Richard L. Woodcock. The following macro initiates the layer command, selects the Make option, pauses for user input for the layer name to be assigned, selects the Color option, pauses for user input for the color name or number to be assigned, selects the Ltype option, pauses for user input for the linetype name to be assigned, selects the Set option,  pauses for user input for the name of the layer to be set current and completes the command. Note that the back slash ( \ ) allows the macro to pause for user input in each case.

    ^C^C-layer;m;\c;\;L;\;s;\;

Macros Are No Panacea

Toolbar macros are best suited for quick'n dirty programming.

There are drawbacks to using toolbar and toolbox macros. The length of the macro is limited to a maximum of 79 or 255 characters, depending on the version of AutoCAD. You are limited to using the icons supplied with AutoCAD; it is extremely difficult to customize the icon. The variety of control characters is extremely limited compared with AutoCAD's other macro and programming languages.

Still, the toolbar is the fastest and most convenient way to minimize keystrokes and mouse clicks in AutoCAD. 


Tailoring AutoCAD Part1 | Part 2 | Part 3 is the next tutorial.

Comments on this tutorial series? Tell me about it.

Return to Contents.

All contents copyright 1995-9 XYZ Publishing, Ltd. . All rights are reserved. No material may be reproduced electronically or in print without written permission from XYZ Publishing, PO Box 3053, Sumas WA, 98295-3053, unless otherwise noted.