AutoCAD
Standardization through customization, part 2
31 Oct, 1998 By: Bill FaneCaptain! Captain! Your column last month on menu customizing really piqued my interest! I must learn more about this so I can properly and easily enforce office CAD standards. Please, please, I need more information!
It was too cold to swim, too windy to water ski, not windy enough to windsurf, and the Rolls-Royce didnt need waxing. Might as well help out. Captain LearnCurve poured another mug of coffee, fired up the laptop, and churned out the following:
Last months column introduced the principles and system managment benefits of menu customizing. This month we look at more details.
Easy as pie
For starters, lets look at an easy way to handle AutoCAD mechanics. In AutoCAD DOS versions, the entire menu structure, including the menu bar, pull-down menus, image or icon menus, digitizer tablets, the screen menu, and what the mouse buttons do, is contained in one monster file. To change anything, you must edit the whole menu file. This can be awkward because its size is more than 100KB in some releases. That is too big for most text editors. To edit a file this big you must use a word processor.
On the other hand, the Windows versions allow partial menu loads. As installed, the menu for Windows releases comes in one large file (which also includes toolbar menus) similar to the DOS ones, but you can create small files that combine within AutoCADs original menu.
This sample menu file creates a custom pull-down menu. You can create the simple text file with Notepad.
Bear with memuch of this will be similiar to last month. Lets take a quick look at some of the new or different lines to see what they do.***MENUGROUP=MyCustom
***POP1
[Lines]
[Part outline]^C^Cclayer part line
[Hidden]^C^Cclayer hidden line
[Center]^C^Cclayer center line
[Section]^C^Cclayer section line
[Construction]^C^Cclayer const xline
// end of menu file
***MENUGROUP=MyCustom.
Each partial menu needs a unique
name. You will see this later when you load it. It doesnt need to be the
same as the filename.***POP1.
If you load this menu file by itself, it is
the first item on the left end of the menu bar. When you do a partial load
into an existing menu, you can specify its exact position. The only requirement
is that each ***POPn
section in a given menu group have a unique
number from 116. [Lines].
Remember that anything within [square brackets]
is a prompt. The first one appears in the menu bar itself. From last months
discussions, I think you can easily see what the next five lines do.Finally, at the end of the
***POP1/
menu section, note that
one blank line must come before the start of the next menu section. Conversely,
any blank lines within the pull-down section make it stop pulling down at
that point. If you want a blank line in a pull-down, use a blank prompt
[]. In menu files, one or more forward slashes (//) indicate a remark that
AutoCAD ignores. I stuck one in here just to make it obvious that a blank
line appears ahead of it at the end of the menu section.One other point. When you save the menu file in Notepad, you must click on Save As Type and select All Files (*.*), then give it a name with an MNS extension, such as test.mns. For now you should save the file into AutoCADs current working directory.
Lets get loaded
To load your partial menu, pick Tools|Customize Menu from the menu bar. This starts the Menuload command that pops up a dialog box with the Menu Groups tab active. Click on the Filename box and type in the name of your menu, such as test.mns. Click Load. It loads if you put it in a directory in the support file search path. If not, browse and go look for it.
Once it loads, note that the
***MENUGROUP
name that you gave
it in the file (in our example, MyCustom) appears in the left-hand Menu
Groups window. Highlight it, then click on the Menu Bar tab.The left window now lists all the
***POPn
pull-down sections
that you defined in the Lines file, while the right window shows the ones
currently displayed in the menu bar (the standard AutoCAD ones).Click on your Lines menu in the left window to highlight it, then click on one of the existing menus in the right window. Clicking Insert adds your menu to the right-hand list immediately above the one that you highlighted. If you change your mind, you can always highlight any menu and remove it.
Click Close and, presto, your new menu item appears in the menu bar. It appears immediately to the left of the one you placed it above during the Menuload operation.
Click on your menu item and it pops down, exactly as defined in your menu file. Click on an item from the pull-down to invoke the exact string of commands and responses that you put in the menu.
As you saw last month, assuming your drawing already contains the layers as specified in the menu (in our example these are PART, HIDDEN, CENTER, SECTION, and CONST), picking a menu item switches you to its layer and starts the Line (or Xline) command.
I think you can see where this is going. Repeat the sample macro with suitable changes to create separate menu picks for things such as circles, arcs, polylines, dimensioning, cross-hatching, and so on. Standardization through customization!
You can experiment with customizing one small section at a time. When you get it working the way you want, you can always go back to the Menuload command and unload any of the standard AutoCAD pull-down sections. AutoCAD remembers things. The next time you open AutoCAD, it automatically loads the remaining bits of the main menu along with your partial menus exactly as you left them.
A gnarly bit
If you edit your partial menu file and want to reload it during the same AutoCAD editing session, you must run Menuload again, unload your menu group, load the file again, and reload your menus back into the menu bar.
More syntax. Release 14 provides complete documentation on customizing menu files and their customizing in the menu bar under Help|AutoCAD Help Topics. When the dialog box comes up, click on the Contents tab, then double-click in sequence Customization Guide|Part 1 - Customization Reference|Chapter 4 Custom Menus. This shows a list of all menu-customizing topics.
Here are a few significant points to get you going, starting with a few reminders from last month.
<Enter>. Menu macros use spaces and semicolons to represent pressing <Enter>. They run exactly the same way if you replace any or all of the semicolons with spaces, and vice versa. On the other hand, every space after the prompts closing bracket is significant. AutoCAD ignores any spaces and tabs ahead of the prompts opening bracket.
\ (backslash). The backslash character in a macro means stop and wait for user input. For example, a macro to insert a block might look like this:
[lamp]insert lamp \;;.
This issues the Insert command,
feeds it the block name lamp, then waits for you to select an insertion
point. The two semicolons tell it to take the default scaling factors.+ (plus sign). Each menu macro can be as long as you want and can contain as many commands and responses as you need. When macros get very long, however, two problems occur: first, they get very difficult to read, and second, earlier DOS versions allow only 255 characters per line.
Normally, AutoCAD reads each line of text as a separate macro. A plus sign at the end of a line tells AutoCAD to carry on and add the next line to the end of the current one. You can repeat this as often as necessary, so a single macro can be several lines long.
Control codes
AutoCAD has a provision for invoking control codes within a macro. The most common usage is to start each macro with the six characters
^C^C^P
.
This tells AutoCAD to issue two <Ctrl>C or <Esc> codes to cancel
any command in process, and a <Ctrl>P to stop the following commands
from echoing to the Command prompt area. Menu operations run faster and
look cleaner. It is often handy to leave the ^P out initially while you
debug and then put it in when you finish.Cascading menus
If a prompt for a pull-down menu begins with the two characters
->
,
AutoCAD doesnt display the next item right away. In fact, it doesnt display
any more choices until it gets to the line following a prompt that begins
with <-. The lines in between make a cascading menu that pops out only
when you pick the first one. For example,***POP2
[Hello]
[->Lines]
[Part]
[hidden]
[center]
[<-section]
[Circles]
:
:
:
When you click on Hello in the menu bar, the pull-down menu shows
only Lines and Circles until you click on Lines, at which time the four
in between appear.Thats amazing! You have taught us all there is to know about menu customizing in just two columns.
We just hit the basicsbut it should be enough to get you started.
And now for something completely different
If you write a monthly magazine column and everyone expects a clever bit at the end, make sure to write down any ideas you may have during the month. When it gets close to deadline, you wont remember them and you wont have one if you havent written them down.
More News and Resources from Cadalyst Partners
For Mold Designers! Cadalyst has an area of our site focused on technologies and resources specific to the mold design professional. Sponsored by Siemens NX. Visit the Equipped Mold Designer here!
For Architects! Cadalyst has an area of our site focused on technologies and resources specific to the building design professional. Sponsored by HP. Visit the Equipped Architect here!