Adding Your Own Pull-Down Menu


In addition to adding buttons and toolbars , AutoCAD lets you add pull-down menu options. This section shows you how to add a custom pull-down menu to your AutoCAD environment.

Creating Your First Pull-Down Menu

Start by trying the following exercise to create a simple pull-down menu file called My Menu:

  1. Using a text editor such as Windows Notepad, create a file called Mymenu.mnu , containing the following lines:

    ***POP1
    [My 1st Menu]
    [Line]^c^c_line
    [ ”]
    [->More]
    [Arc-SED]^c^c_arc \_e \_d
    [<-Break At]^c^c(defun c:breakat ()+
    (command "break" pause "f" pause "@")+
    );breakat
    [ Fillet 0]^c^c_fillet r 0;;
    [Point Style X]'pdmode 3
    ***POP2
    [My 2nd Menu]
    [door]^c^cInsert door
    [Continue Line]^C^CLINE;;

  2. Save this file and be sure you place it in your \AutoCAD2005\Support\ folder.

    Warning  

    Pay special attention to the spaces between letters in the commands described in this chapter. (You need not worry about whether to type uppercase or lowercase letters .)

    Warning  

    The Breakat menu item uses AutoLISP, which is not supported by LT. It is used in the example to show AutoCAD 2005 users that AutoLISP can be embedded in the menu.LT users can still write the menu as shown but just be aware that the Break At option will not work.

    Warning  

    After you've stored the file, you have your first custom pull-down menu. You might have noticed some familiar items among the lines you entered. The menu contains the Line and Arc commands. It also contains the Breakat macro you worked on in the previous chapter; this time, that macro is broken into shorter lines.

Now let's see how My Menu works in AutoCAD.

Loading a Menu

In the following exercise, you will load the menu you just created and test it. The procedure described here for loading menus is the same for all menus , regardless of their source:

  1. Choose Tools   Customize   Menus to open the Menu Customization dialog box.

    click to expand
  2. Make sure that the Menu Groups tab is selected. Then click Browse to open the Select Menu File dialog box.

  3. Click the Files Of Type drop-down list and then select Menu Template (*.mnu).

  4. Locate the Mymenu.mnu file, highlight it, and then click Open. You return to the Menu Customization dialog box.

  5. Click Load. You see a warning message telling you that you will lose any toolbar customization you have made. This refers only to the specific menu you are loading. Because you haven't made any toolbar customization changes to your menu, you won't lose anything.

  6. Click Yes. The warning dialog box closes , and you see the name of your menu group in the Menu Groups list box.

  7. Click the Menu Bar tab. The dialog box changes to show two lists. On the left is the name of the current menu group. The list on the right shows the currently available pull-down menus.

    click to expand
  8. Click the Menu Group drop-down list and select Mymenu. The names of the pull-down menus in your menu file appear.

  9. Highlight Help in the column on the right. This tells AutoCAD that you want to add your pull-down menu in front of the Help pull-down menu.

  10. Highlight My 1st Menu in the list on the left and then click the Insert button. My 1st Menu moves into the column on the right, and it appears in the AutoCAD menu bar.

    click to expand
  11. Highlight My 2nd Menu from the list on the left, and then click Insert again. My 2nd Menu is copied to the column on the right, and it also appears in the menu bar.

    click to expand
  12. Close the Menu Customization dialog box.

  13. Draw a line on the screen and then choose My 1st Menu   More   Break At.

    click to expand

With just a 15-line menu file, you created a menu that contains virtually every tool used to build menus.

In step 5, you saw a warning message about customization changes. When you load an AutoCAD.mnu file, AutoCAD creates a set of new files that it uses to work with your menu. These files have the extensions .mns, .mnr, and .mnc. You usually don't have to worry about the .mnr and .mnc files because AutoCAD manages these files. However, when you load your .mnu file for the first time, AutoCAD creates and uses the .mns file, which is a reformatted copy of your .mnu file. This reformatted file contains additional sections AutoCAD needs for its operation. For this reason, you should make changes and edit the .mns file for your menu. For example, if you want to make additional changes to your Mymenu menu, edit Mymenu.mns rather than Mymenu.mnu . This way, if you add custom toolbars or custom keyboard macros, you won't lose them when you make changes to your menu file.

Tip  

After you've created your own menu file and loaded it, you can add custom toolbars and tools to it just as you did with the Custom menu in the first part of this chapter. This way, you can keep your custom tools in one place.

Now let's take a more detailed look at how menu files work.

Understanding How the Pull-Down Menu Works

Let's take a closer look at the Mymenu.mns file. The first item in the file, ***POP1 , identifies the beginning of a pull-down menu. The text just below the first line is My 1st Menu enclosed in square brackets. This is the title of the pull-down menu; this text appears in the toolbar. Every pull-down menu must have this title element.

Following the title, each item in the list starts with a word enclosed in brackets; these words are the options that appear when you open the pull-down menu. If you were to remove everything else, you would have the menu as it appears on the screen. The text that follows the item in brackets conveys instructions to AutoCAD about the option.

Finally, in the My 1st Menu sample, you see ***POP2 . This is the beginning of a second pull-down menu. Again, you must follow this with a pull-down menu title in square brackets. Below the title, you can add other menu options.

Calling Commands

Now look at the Line option in the Mymenu.mnu listing. The two Ctrl+C ( ^C ) elements that follow the square brackets cancel any command that is currently operative . The Line command follows, written just as it would be entered through the keyboard. Two Cancels are issued in case you are in a command that has two levels, such as the Edit Vertex option of the Pedit command (Modify   Object   Polyline).

The underscore character ( _ ) that precedes the Line command tells AutoCAD that you are using the English-language version of this command. This feature lets you program non-English versions of AutoCAD by using the English-language command names.

You might also notice that there is no space between the second ^C and the Line command. A space in the line would be the same as . If there were a space between these two elements, would be entered between the last ^C and the Line command, causing the command sequence to misstep. Another way to indicate is by using the semicolon, as in the following example:

[Continue Line]^C^CLINE;;

Tip  

If a menu macro contains multiple instances of , using semicolons instead of spaces can help make your macro more readable.

In this sample menu option, the Line command is issued, and then an additional is added. The effect of choosing this option is a line that continues from the last line entered into your drawing. The two semicolons following Line tell AutoCAD to start the Line command and then issue twice to begin a line from the endpoint of the last line entered. (AutoCAD automatically issues a single at the end of a menu line. In this case, however, you want two instances of , so they must be represented as semicolons.)

Pausing for User Input

Another symbol used in the menu file is the backslash ( \ ); it is used when a pause is required for user input. For example, selecting the Arc-SED option in My 1st Menu starts the Arc command and then pauses for your input.

[Arc-SED]^c^c_arc \_e \_d

Tip  

The underscore character ( _ ) that precedes the command name and option input tells AutoCAD that you are entering the English-language version of these commands.

The space between ^c^c_arc and the backslash ( \ ) represents pressing the spacebar. The backslash indicates a pause to enable you to select the starting endpoint for the arc. After you have picked a point, the _e represents the selection of the Endpoint option under the Arc command. A second backslash allows another point selection. Finally, the _d represents the selection of the Direction option. Figure 20.1 illustrates this. If you want the last character in a menu item to be a backslash, you must follow the backslash with a semicolon.

click to expand
Figure 20.1: The execution of the Arc menu item

Using the Plus Sign for Long Lines

As you browse through the Acad.mnu file, notice that many of the lines end with a plus sign ( + ). The length of each line in the menu file is limited to about 80 characters , but you can break a line into two or more lines by adding a plus sign at the end of the line that continues, like this:

[<-Break At]^c^c(defun c:breakat ()+
(command "break"pause "f"pause "@")+
);breakat

This example shows how to include the Breakat AutoLISP macro in a menu. Everything in this segment is entered just as it would be with the keyboard. The plus sign indicates the continuation of this long item to the subsequent lines, and the semicolon is used in place of .

Tip  

It's okay to break an AutoLISP program into smaller lines. In fact, it can help you read and understand the program more easily. LT does not support AutoLISP.

Creating a Cascading Menu

Look at the More option in the File pull-down menu group; it starts with these characters: -> . This is the way you indicate a menu item that opens a cascading menu. Everything that follows the [->More] menu item will appear in the cascading menu. To indicate the end of the cascading menu, you use the characters <- , as in the [<-Rotate90] menu item farther down. Anything beyond this <- item appears in the main part of the menu. If the last item in a cascading menu is also the last item in the menu group, you must use <-<- , as in [<-<-.XZ] .

Placing Division Lines and Dimmed Text in Pull-Down Menus

Two symbols are used to place dividing lines in your pull-down menus:

Double-hyphen symbol ( -- )     This is used to divide groups of items in a menu; it will expand to fill the entire width of the pull-down menu with a line of hyphens.

Tilde symbol ( ~ )     If the tilde precedes a bracketed option name, that option will be dimmed when displayed; when clicked, it will have no effect.

You have probably encountered these dimmed options on various pull-down menus in the programs you use. When you see a dimmed menu item, it usually means that the option is not valid under the current command.

start sidebar
Loading AutoLISP Macros with Your Submenu

As you become a more advanced AutoCAD user, you might want many of your own AutoLISP macros to load with your menus. You can accomplish this by combining all your AutoLISP macros into a single file. Give this file the same name as your menu file but with the .mnl filename extension. Such a file will automatically load with its menu counterpart . For example, say you have a file called Mymenu.mnl containing the Breakat AutoLISP macro. Whenever you load Mymenu.mns , Mymenu.mnl is automatically loaded along with it, giving you access to the Breakat macro. This is a good way to manage and organize any AutoLISP program code you want to include with a menu.

end sidebar
 

Adding a Help Message

Earlier in this chapter, you learned how to include a help message with a button. The help message appears in the status bar of the AutoCAD window when you highlight an option. You can also include a help message with a pull-down menu item.

First, you must give your pull-down menu file a menu group name. This helps AutoCAD isolate your file and its help messages from other menus that might be loaded along with yours. To give your menu file a group name, add the following line at the top of the file:

***MENUGROUP= MYMENU

MYMENU is the name you want for your menu group name.

Next, you have to add an ID name to each menu item that requires a help message. The following shows how this might be done for the My 1st Menu example you used earlier:

***MENUGROUP=MYMENU
***POP1
[My 1st Menu]
ID_1line [Line]^c^c_line
[ ”]
[->More]
ID_1arc-sed [Arc-SED]^c^c_arc \_e \_d
ID_1breakat [<-Break At]^c^c(defun c:breakat ()+
(command "break" pause "f" pause "@")+
);breakat
ID_1fillet0 [Fillet 0]^c^c_fillet r 0;;
ID_1pointx [Point Style X]'pdmode 3
***POP2
[My 2nd Menu]
[door]^c^cInsert door
[Continue Line]^C^CLINE;;

The ID name starts with the characters ID followed by an underscore character ( _ ) and then the name for the menu item. Several spaces are added so that the menu items align for clarity. Each menu item must have a unique ID name.

Finally, you add a section at the end of your file called ***HELPSTRINGS . For this example, it would look like the following code:

***HELPSTRINGS
ID_1line [Draws a line]
ID_1arc-sed [Draws an arc with start, end, direction]
ID_1breakat [Breaks an object at a single point]
ID_1fillet0 [Sets the Fillet radius to zero]
ID_1pointx [Sets the Point style to an X]

The menu item ID names are duplicated exactly, followed by several spaces, and then the actual text you want in the status bar, enclosed in brackets. The spaces between the ID and the text are for clarity.

Warning  

The ID names are case sensitive, so make sure they match up in both the HELPSTRINGS section and in the menu section.

After you've done this and then loaded the menu file, you will see these same messages appear in the status bar when these menu options are highlighted. In fact, if you browse your Acad.mnu file, you will see similar ID names. If you prefer, you can use numbers in place of names.




Mastering AutoCAD 2005 and AutoCAD LT 2005
Mastering AutoCAD 2005 and AutoCAD LT 2005
ISBN: 0782143407
EAN: 2147483647
Year: 2004
Pages: 261
Authors: George Omura

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net