Customizing Your Pulldown Menus1 Apr, 1999 By: Lynn Allen
We've spent the past two months exploring the world of customizing, and the responses I've had via email have been amazing! I had no idea so many of you had wandered into the web of customizing, only to become entangled in its myriad semicolons and backslashes.
A new release of AutoCAD will be out soon, but you'll find that the information contained within these three customizing articles will remain valid for those who jump on the upgrade wagon. This month, we'll look at another type of menu-more notably the popular pulldowns. You'll find the same menu syntax that worked for our toolbars, also applies to other types of menus.
A quick refresher on menu syntax:
; indicates an [Enter].
\ pauses for user input.
^C^C is used to cancel out of an existing command and is important to ensure our macros work effectively.
^C^CERASE;L;; executes two cancels to ensure the user is at the command prompt. Then executes the ERASE command, [Enter], the L (for last) option and finally two [Enters] ensures the user is back at the command prompt after executing the command.
^C^Cinsert;door;\;;\ cancels out of the existing command, executes the INSERT command, [Enter], uses DOOR as the block name, [Enter], pauses for the user to select the insertion point, uses the default of 1 as the x and y scale factors and pauses once more so the user could determine the rotation angle of the inserted block.
That's quite a mouthful! You'll find that you need to know the sequence of the AutoCAD commands in order to write your macros.
Creating a Pulldown Menu
We're going to create our own, very simple pulldown menu for starters. I'm afraid you're not going to want to throw away the AutoCAD menu and use this one; it's primarily for practice. This can be done in any text editor that can output plain old ASCII text.
If you recall from the first article in the series, all major menu divisions have three asterisks in front of the menu type. The following are the menus supported in any AutoCAD menu file:
***Buttons1,2,3 or 4
***AUX1,2,3 or 4
Each of these sections was covered in detail in the first customizing article. Our simple menu is going to start with just one of these sections: ***POP. A quick reminder that ***POP0 is used to customize the cursor menu and ***POP1-16 are used to customize the pulldowns that reside across the top of your AutoCAD drawing area. You cannot create a menu with just a cursor menu (POP0), you must have at least one pulldown menu as well (just a little idiosyncrasy). Also for the record, if you create a menu file with no pulldown menu files defined, AutoCAD automatically inserts default file and edit menus whether you like it or not!
The Menu File
Using any standard text editor, key in the following syntax into your menu file. Save the file under the name of sample.mnu, and then we'll talk about each line in detail.
[&Annoying display items]^C
The first line of a pulldown menu (also known as pop-up menu) contains the menu bar title. The title of this pulldown is Misc. The title goes within brackets; no macro is to be assigned to it as found in the other menu items. All pulldown menus must have a menu title. Even though the cursor menu doesn't display a title, one must be included (so go ahead and name it after your dog!).
The ampersand is used to indicate a mnemonic key, so you place the ampersand in front of the character you want to be the mnemonic. You'll notice on all of your AutoCAD pulldown menus that one of the characters on each entry is underscored. This is the mnemonic key (also referred to as a menu accelerator key). For example, in our SAMPLE menu, Alt-M pulls down the Misc menu. In the AutoCAD menu, Alt-F pulls down the Files menu. Once you've selected a pulldown from the keyboard, specific menu options can be selected by entering the underscored character in the desired menu line. Alt-M, followed by a Z executes the ZAP menu item.
You usually select a unique character per pulldown. In other words, you won't have the character C used more than once as a mnemonic. If more then one option uses the same mnemonic, you'll find yourself cycling between the two when driving the pulldown via the keyboard. It's also bad customizing manners. Notice that in our Sample menu, there are two options that start with the Character Z: Zap and Zoom. Zap uses the Z as the mnemonic while Zoom uses the first "o".
The lines of code beneath [&Misc] are lines within our pulldown menu. The characters within the brackets [ ] indicate the text you want to appear on the screen. The code outside of the bracket indicates the macro we want executed when the menu item is selected.
Let's review this line of code:
The word Zap appears as the first option available on our pulldown, and the Z will be the mnemonic key. When selected, AutoCAD issues two Cancels, the ERASE command, an [Enter], the ALL option, another [Enter] and ends with an extra enter to take the user all the way back to the command prompt.
Let's skip to the third menu item in our pulldown:
The word Square would appear on the pulldown menu with the "S" being the mnemonic. When selected, AutoCAD enters two cancels followed by the POLYGON command and then [Enter]. When prompted for Number of sides, AutoCAD selects 4 and E for the Edge option, which is selected next. AutoCAD then hits an [Enter] and pauses twice so the user can select the two endpoints defining one edge of the square. If this sounds like Greek to you, execute the POLYGON command in AutoCAD and follow through the steps.
Notice the line that contains [-]. This line draws a separator line in the pulldown menu the width of the longest title. Separators are typically used as dividers between different command categories or just to make it easy on the eyes. The user cannot select a separator line, and no macros are defined in conjunction with them.
Continuing on down to the next menu item:
The word Zoom shows up on the screen, and you'll notice that the "o" is the mnemonic. You'll also see that the Cancels are missing and have been replaced with an apostrophe. Why? Because the ZOOM command is a transparent command. It can be executed within another command as long as you preface it with an apostrophe. What if users wanted to execute this menu item and remain in the LINE command? They wouldn't be happy if our menu item needlessly cancelled them out (hence the apostrophe).
If you find yourself with an extra long macro that needs to continue on to the next line, you'll need to place a "+" at the end of the line of code. Otherwise, AutoCAD will assume the next line of macro programming is intended for an entirely different menu item.
Using the Menu
After you create the simple menu, save it and load it into AutoCAD.
To use this menu, we'll need to execute the MENU command. As a reminder, once you load an MNU file, AutoCAD automatically creates an MNS and compiles an MNC file. If you decide to make changes to the MNU file, reselect that specific file extension. (Note: AutoCAD will issue an evil warning statement indicating that you will lose any of your custom toolbars. Not to worry because we don't have any custom toolbars in our sample menu.)
Select the sample menu and you should see the pulldown menu in the upper left-hand corner of your screen. Try the different menu items to make sure they work.
To ensure I don't leave you out in limbo, you can always get back to the AutoCAD menu by loading the acad.mns file from the AutoCAD Support directory. If you've created any custom toolbars, be sure you don't load the MNU by mistake (they will mysteriously disappear!).
Now, as I pointed out earlier, I doubt you'd want to throw the AutoCAD menu by the wayside and use your own custom menu. More than likely you'd prefer to do one of the following:
- Wedge your custom pulldown menu into the existing AutoCAD menu by using the MENULOAD command.
- Modify the acad.mns file adding commands into the existing pulldown menus or adding an entirely new pulldown.
Until next month!
In her easy-to-follow, friendly style, long-time Cadalyst contributing editor Lynn Allen guides you through a new feature or time-saving trick in every episode of her popular AutoCAD Video Tips. Subscribe to the free Cadalyst Video Picks newsletter, and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!