Tải bản đầy đủ (.pdf) (132 trang)

AutoCAD Basics 2004 bible phần 9 ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.32 MB, 132 trang )

1014
Part VI ✦ Customizing AutoCAD
name of the file to edit, and Windows opens it in Notepad. (You need to type in the
complete path of the file.) To open Notepad without a file, press Enter at the
*File
to edit:
prompt.
Creating keyboard shortcuts to commands
Most of the acad.pgp file contains aliases, or keyboard shortcuts, for common
AutoCAD commands. You can change these or add your own. After you get used to
them, it’s often faster to type shortcuts at the command line than to click the tool-
bar button or menu item, especially if your hands are already on the keyboard.
You cannot include a command option in the
acad.pgp file. To do that, you need
to create a menu item, toolbar button, or AutoLISP routine.
The Express Tools contain an Alias Editor that enables you to edit the acad.pgp
file through a dialog box interface. Choose Express ➪ Tools➪Command Alias
Editor.
The format for creating an alias is as follows:
Shortcut,*Full command name
Refer back to Figure 29-1 for some examples of shortcuts. Note that the space
between the columns is not necessary — it simply improves readability.
You can use aliases transparently if the command itself can be used transparently.
Aliases cannot be used in script files or menus. Note that you cannot use control or
function keys in command aliases in the
.pgp file.
You can print out acad.pgp and tape it up on the wall where you work.
If you are working on someone else’s computer, do not do the following Step-by-
Step exercise without that person’s permission. It is not good computer etiquette
to modify other people’s AutoCAD files without asking first.
Step-by-Step: Customizing the acad.pgp File


1. Start AutoCAD.
2. Place a blank disk in your floppy disk drive. Type explorer ↵. After opening a
preliminary window, AutoCAD opens Windows Explorer using the
acad.pgp
shortcut.
Caution
Tip
New
Feature
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1014
1015
Chapter 29 ✦ Customizing Commands, Toolbars, and Tool Palettes
By default, acad.pgp is in \Documents and Settings\[user name]\
Application Data\Autodesk\AutoCAD 2004\R16.0\enu\Support. However,
your location may be different, depending on your operating system and customiza-
tion. To find the location of acad.pgp, choose Tools➪ Options and click the Files tab.
Double-click the first item, Support File Search Path, to display the location of the
support files.
3. Find acad.pgp, click it, and drag it to the drive (in the Folders window) that
contains your floppy disk. Windows copies
acad.pgp to the disk. If you
haven’t already backed up your other customizable files, copy
acad.lin,
acad.lsp, acad.mln, acad.mnl, acad.mnu, and acad.pat to the disk as well.
(If they don’t fit, you may need to use two disks or a CD-ROM.) Remove the
disk and label it “AutoCAD customizable files — original form.”
4. While Explorer is open, double-click
acad.pgp. Windows opens the file in
Notepad. (If Windows opens the Open With dialog box, choose Notepad from
the list. Check the Always Use This Program To Open This File option and

click OK. From then on, Windows will automatically open your
acad.pgp file
with Notepad. (Another method is to right-click and then choose Open With
to choose the application you want to use.)
5. Scroll down roughly two screens until you see the three Windows commands,
as shown in Figure 29-2. Place the cursor at the end of the PBRUSH line and
press Enter.
Figure 29-2: The Windows commands
in the
acad.pgp file
6. Type the following and press Enter (the uppercasing and spaces are used to
match the format of the rest of the file):
WORDPAD, START WORDPAD, 1,,
7. Look at the next section of acad.pgp. Read AutoCAD’s guidelines for creating
new aliases.
8. Scroll down until you see the following two lines:
CH, *PROPERTIES
-CH, *CHANGE
The alias for the CHANGE command follows the guideline of using a hyphen to
distinguish command-line versions of commands. Suppose you have trouble
finding that hyphen quickly (you end up typing
=ch instead). You want to
change the alias to
cg (with no hyphen).
Note
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1015
1016
Part VI ✦ Customizing AutoCAD
9. To be extra careful, add a new alias rather than changing the current alias
(which someone may be in the habit of using). Place the cursor after the word

*CHANGE and press Enter. Type the following and press Enter (don’t worry
about the spaces — I’ve matched the spacing of the
acad.pgp file):
CG, *CHANGE
10. Choose File ➪ Save. This section of acad.pgp that you worked on should look
like Figure 29-3.
Figure 29-3: A section of the edited acad.pgp file
11. Close Notepad. Generally, AutoCAD only reads acad.pgp when loading a new
or existing drawing. However, you can use the REINIT command to reload the
file at any time. Type reinit ↵. AutoCAD opens the Re-initialization dialog box,
as shown in Figure 29-4.
Figure 29-4: The Re-initialization dialog box
12. Check PGP File and click OK. In your drawing, draw any line.
13. Type cg ↵. AutoCAD starts the CHANGE command. Select the line, right-click
to end selection, and pick a new endpoint location. AutoCAD changes the
endpoint of the line.
14. Do not save your drawing.
The edited acad.pgp file is on the CD-ROM in the Results folder. Although you
made only two changes, if you want, you can copy the acad.pgp file from the
CD-ROM over your original acad.pgp file. Of course, you can make additional
changes to suit your needs.
On the
CD-ROM
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1016
1017
Chapter 29 ✦ Customizing Commands, Toolbars, and Tool Palettes
Customizing Toolbars
In the Windows environment, you frequently find yourself using toolbar buttons for
many of your tasks. Nevertheless, how many times have you found yourself typing
a command because you couldn’t quickly find an equivalent button on a toolbar,

or because it was on a flyout that was too annoying to deal with? In addition, think
how often you start a command with a toolbar button, only to return to the keyboard
to type in a simple option.
You can customize AutoCAD’s toolbars to make your work easier and faster. You
can create new toolbars from scratch, or edit existing ones. You can even create
your own toolbar buttons. When you create a toolbar button, you can attach any
sequence of commands to it — a complex macro or even an AutoLISP expression.
Using the Customize dialog box
The Toolbars tab of the Customize dialog box (choose View➪ Toolbars), shown in
Figure 29-5, combines all the tools you need to manage toolbars.
Figure 29-5: The Toolbars tab of the Customize
dialog box
To display a toolbar, you don’t need to use the Toolbars dialog box. You can right-
click any toolbar and choose from the list on the shortcut menu. However, you can
also display toolbars from the Toolbars tab of the Customize dialog box by check-
ing the toolbar you want to see. Both lists include flyouts. It is therefore very easy
to turn a flyout into a toolbar if you want — click the flyout—for example, Zoom —
and it appears as a regular toolbar.
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1017
1018
Part VI ✦ Customizing AutoCAD
You also use the Toolbars tab of the Customize dialog box to create new toolbars,
delete toolbars, and customize existing toolbars. If you create your own menus,
they can have toolbars as well. You can then choose toolbars from your menus
using the Menu Group drop-down list.
Creating a new toolbar
To create a new toolbar, choose New in the Toolbars dialog box. In the New Toolbar
dialog box, shown in Figure 29-6, name your toolbar (and the Menu Group if you
have created one) and then click OK. Your toolbar now appears in the Toolbars list
of the Toolbars dialog box, and a small, new toolbar appears on the screen, as

shown in Figure 29-7.
You use menu groups when you start to create your own menus. For more on
Menu Groups, see Chapter 33, which covers customizing menus.
Figure 29-6: The New Toolbar
dialog box
Figure 29-7: The new toolbar shown in the Toolbar list
and on the screen
Cross-
Reference
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1018
1019
Chapter 29 ✦ Customizing Commands, Toolbars, and Tool Palettes
The new toolbar is just a baby, but as you add buttons to it, it grows automatically.
An important part of managing toolbars is finding a place to dock them so that
they don’t take up valuable real estate on the screen. You can make several small
toolbars and fit them in the blank spaces next to existing toolbars. The AutoCAD
2004 Standard toolbar is shorter than the previous one and gives you more room
for your own toolbars.
Removing buttons
You can customize any toolbar by removing buttons that you rarely use. To remove
buttons from a toolbar, follow these steps:
1. Display the toolbar.
2. Choose View ➪ Toolbars to display the Customize dialog box. If necessary,
move it out of the way so you can access the toolbar that needs a button
removed.
3. Drag the unwanted button off the toolbar and onto the screen area and
release the mouse button.
It’s easy to forget that you need to have the Customize dialog box open to remove
buttons because there’s no direct connection between dragging buttons off the
toolbar and the dialog box —but you can’t drag buttons off a toolbar unless the

dialog box is open. Inadvertently dragging a button off the Customize Toolbars dia-
log box is also easy —if you do, you create a new toolbar.
Adding buttons
If you have created a new toolbar, you need to add buttons to it. You have several
ways to do this:
✦ Add a button from the Commands tab of the Customize dialog box. Display
the Commands tab of the Customize dialog box and choose a category.
AutoCAD provides a number of preset buttons in each category (including
many of the flyout buttons from Release 13). You can also choose All
Commands in the Category pane and then choose any command from the
alphabetical Commands list. Click a button to see its description at the
bottom of the dialog box. When you have found the button you want, drag
it to your new toolbar.
✦ Move a button from another toolbar. With the Customize Toolbars dialog box
open, drag a button from one open toolbar to your new toolbar. This moves
the button, deleting it from the original toolbar.
✦ Copy a button from another toolbar. If you want to leave the original toolbar
intact, use the same technique as for moving a button, but hold down the Ctrl
key as you drag a button from one open toolbar to your new toolbar. This pro-
cedure copies the button.
Note
Tip
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1019
1020
Part VI ✦ Customizing AutoCAD
Creating your own button definition
You can also create your own button definition from scratch. Follow these steps:
1. With the Commands tab of the Customize dialog box displayed, choose User
Defined from the Categories list. The Commands pane lists a User Defined
Button and User Defined Flyout.

2. Drag the button you want onto your toolbar. Because the buttons have no
borders, they are indistinguishable from the background until you click them.
3. Click the Properties tab of the Customize dialog box and then click the blank
button to display the Button Properties tab of the Customize dialog box, as
shown in Figure 29-8.
Figure 29-8: The Button Properties tab of the
Customize dialog box
4. Type a name for the button. This name appears as a tooltip, so don’t make it
too long.
5. Type a help description in the Help text box. This text appears on the status
line to further explain the function of the button.
6. Write the macro. AutoCAD places
^C^C there for you. This cancels any other
command that may be active when you use the button. You can place any
valid menu command string as it would be typed on the command line or
even an AutoLISP expression.
You should use menu syntax for the macro. I explain the details of creating
command strings in Chapter 33, where I cover customizing menus.
Cross-
Reference
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1020
1021
Chapter 29 ✦ Customizing Commands, Toolbars, and Tool Palettes
7. Choose a button icon from the list of button icons or choose Edit to create
your own button, as explained in the next section.
8. Click Apply and click the Close button of the Customize dialog box to close it.
Close any other open dialog boxes.
AutoCAD updates the menus, showing its progress on the status bar.
Using the Button Editor
The Button Editor, shown in Figure 29-9, enables you to make your own button

icons. Open the Button Editor by clicking Edit on the Button Properties tab of the
Customize dialog box. You can choose one of the provided buttons and edit it —
which I recommend—or start from scratch if you have artistic tendencies.
Figure 29-9: The Button Editor
The center of the editing area shows an enlarged view of the button. You see the
button’s actual size at the top-left corner of the dialog box. Check Grid to show a
grid of pixels — this is just for your reference. Choose a color from the color palette
and then choose one of the four tools at the top of the dialog box:
✦ The Pencil tool draws any shape. To draw, drag it across the editing area.
✦ Click and drag the Line tool to draw a straight line.
✦ The Circle tool draws circles and ellipses. You click the center and drag out
to the circumference to indicate the radius.
✦ The Erase tool erases. You can click to erase pixel by pixel or drag to erase a
series of pixels.
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1021
1022
Part VI ✦ Customizing AutoCAD
Here are the other features of the Button Editor:
✦ Choose Clear to clear the editing area and start from scratch.
✦ Choose Open to open an existing button for editing. Button icons are stored
as
.bmp files.
✦ Choose Undo to undo your most recent action.
✦ Choose Save to save the button icon as a
.bmp file. The default file name is
ICON.bmp.
✦ Choose Save As to save an existing
.bmp file under a new name.
✦ Choose Close to close the Button Editor.
✦ Choose More to select a standard index color or true color.

With the introduction of true color support in AutoCAD 2004, you can now create
your toolbar icons with a wider variety of colors. Choose More in the Button Editor
dialog box (shown in Figure 29-9) to access this colorful new feature.
Creating flyouts
You can also create your own flyouts, or you can use one of the existing flyouts.
To use an existing flyout, open the Commands tab of the Customize dialog box
and choose Flyouts. You can simply drag one of these to a toolbar.
To create your own flyout, follow these steps:
1. Create a toolbar with the buttons that you want on the flyout, as explained in
the previous section.
2. Open the Customize dialog box and display the Commands tab.
3. Choose User Defined from the Categories list and drag User Defined Flyout
from the Commands list onto an existing toolbar. You see a blank flyout on the
toolbar.
4. Click the Properties tab of the Customize dialog box and then click the blank
flyout button to display the Flyout Properties tab, shown in Figure 29-10.
4. You see a message telling you to associate a toolbar with the flyout.
5. From the list of toolbars, choose the new toolbar that you created. This tool-
bar will be the flyout from the flyout button you just added.
6. Click Apply and then click Close.
7. Your new toolbar is now a flyout on a toolbar. You can close the new toolbar
you created because you can access it from its parent toolbar.
New
Feature
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1022
1023
Chapter 29 ✦ Customizing Commands, Toolbars, and Tool Palettes
Figure 29-10: The Flyout Properties tab of the
Customize dialog box
The following exercise changes your menu files. After the exercise, I explain how to

undo the changes if you want. If you are working on someone else’s computer, do not
do this exercise without that person’s permission. As I mentioned before, it is not
good computer etiquette to modify other people’s AutoCAD files without asking first.
Step-by-Step: Customizing Toolbars
1. Open Windows Explorer and copy acad.mnu, acad.mnc, and acad.mns from
the
AutoCAD 2004\Support folder to a floppy disk. Label and date the disk.
By default, acad.mnu, acad.mnc, and acad.mns are in \Documents and
Settings\[user name]\Application Data\Autodesk\AutoCAD 2004\
R16.0\enu\Support. However, your location may be different, depending on
your operating system and customization. To find the location of acad.mnu,
acad.mnc, and acad.mns, choose Tools ➪ Options and click the Files tab.
Double-click the first item, Support File Search Path, to display the location of the
support files.
2. Start a new drawing using any template. Save the file as ab29-01.dwg in your
AutoCAD Bible folder.
3. Choose View ➪ Toolbars to open the Customize dialog box. From the Toolbars
list, scroll down to find the Zoom toolbar and check it. When it appears, drag
it away from the Toolbars dialog box, if necessary.
4. Drag the Zoom Center and Zoom All buttons off the toolbar (or choose the
two buttons that you use least and drag them off), confirming the deletion
each time. A small space appears between the last (Zoom Extents) button and
the rest of the buttons. Drag the Zoom Extents button to the left slightly to
eliminate the space.
Note
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1023
1024
Part VI ✦ Customizing AutoCAD
5. Drag the toolbar to the space at the right of the Standard toolbar and dock it
there. (The space you have depends on the size of your screen and your

screen resolution. If it doesn’t fit, drag one more button off the toolbar or
dock it on the right side of the screen.)
6. Choose New on the Toolbars tab. In the New Toolbar dialog box, type Special
in the Toolbar Name text box and click OK. A small toolbar appears on your
screen.
7. Click the Commands tab. From the Categories list, choose Draw. Find the
Donut button and drag it to your new toolbar. The I-beam cursor on the
toolbar indicates the button placement.
8. Choose the Modify category and find Edit Polyline. Drag it to your new
toolbar.
9. Choose the View category and drag Hidden to the toolbar.
10. Choose the User Defined category and drag User Defined Button to the new
toolbar. Click the blank button to display the Button Properties tab.
11. Complete the dialog box, as shown in Figure 29-11. Type the macro as follows
after the
^C^C, which is already there, being careful to include the spaces
as well:
pedit \w .1 ;
12. Choose the Polyline Edit button from the Button Icon list, as shown in Figure
29-11. Choose Edit to open the Button Editor.
Figure 29-11: The completed Button Properties
dialog box
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1024
1025
Chapter 29 ✦ Customizing Commands, Toolbars, and Tool Palettes
13. You want to change the button so that it looks as if a zero-width polyline is
being changed to a wider polyline because that’s what the macro does. Click
the red color. Choose the pencil tool (by default, it is already chosen). Click
Grid to help you work. Click (or drag) the point of the pencil tool in each box,
using Figure 29-12 as a guide. (Figure 29-12 shows the button in black and

white.) When you’re done, choose Save and then Close.
Figure 29-12: The new button
If you make a mistake, it’s easy to correct it. If you place a red pixel over an exist-
ing black pixel, choose black and redraw the black pixel. If you place a red pixel in
a wrong spot, choose the Erase tool and click the pixel.
14. On the Button Properties tab, click Apply. The new button appears in your
toolbar. Click the Close button to close the dialog box. AutoCAD saves the
changes to your menu source file (
.mns).
15. Drag the new toolbar under the Zoom toolbar you modified. (If it doesn’t fit,
dock it on the right side of the screen.)
16. Choose Polyline from the Draw toolbar and draw any series of polyline
segments. Choose the Plines .1 wide button from the new toolbar. At the
Select polyline: prompt, pick the polyline. AutoCAD changes its width to
0.1. (If it doesn’t work, check the macro. Right-click the Plines .1 wide button,
choose Customize, and click the Plines .1 wide button to open the Button
Properties tab.)
17. Save your drawing.
If you later customize the ACAD menu by editing acad.mnu, your toolbar modifi-
cations will be erased! In Chapter 33, where I discuss customizing AutoCAD’s
menus, I explain how to avoid this problem.
Caution
Tip
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1025
1026
Part VI ✦ Customizing AutoCAD
Undoing toolbar changes
To undo your toolbar changes, you need to reload the template menu, acad.mnu. This
overwrites the compiled and source menu files that include your toolbar changes. The fol-
lowing steps explain the process. But first, be sure to have a backup of your

acad.mnu,
acad.mnc, and acad.mns files. (To find the location of the menu files, choose Tools➪
Options and click the Files tab. Double-click the first item, Support File Search Path, to dis-
play the location of the support files.)
1. Choose Tools ➪ Customize➪ Menus. The Menu Groups tab should be on top. In the
Menu Groups box, ACAD should be highlighted, as shown here.
2. In the bottom section of the dialog box, check Replace All so that AutoCAD loads all
your menu files on the menu bar. In the File Name box, type acad.mnu and click
Load. When you load the
acad.mnu file, AutoCAD warns you that you will lose any
toolbar customization changes you have made, as shown in the following figure.
Click Yes because you do want to overwrite all your toolbar customization changes.
3. AutoCAD loads the menu and displays the message Menu loaded successfully.
MENUGROUP: ACAD
. Click Close. Your new toolbars and buttons disappear.
Reloading
acad.mnu would remove any partial menus that you may have loaded. For more
information, see my coverage of menu files in more detail in Chapter 33.
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1026
1027
Chapter 29 ✦ Customizing Commands, Toolbars, and Tool Palettes
Here’s how the pedit macro you used in the previous Step-by-Step exercise works:
pedit \w .1 ;
1. Pedit issues the PEDIT command. The space after pedit is equivalent to
pressing Enter after you have typed the command on the command line.
PEDIT then displays the
Select polyline: prompt.
2. The backslash (\) is a special character that pauses the macro for your input.
When you select the polyline, the macro continues, displaying the
Enter an

option [Close/Join/Width/Edit vertex/Fit/Spline/Decurve/Ltype
gen/Undo]:
prompt.
3. The
w then specifies the Width option. The space following it is like pressing
Enter. PEDIT then displays the
Specify new width for all segments:
prompt.
4. The macro then specifies 0.1. The space after it is like pressing Enter again.
PEDIT then issues the
Enter an option [Close/Join/Width/Edit
vertex/Fit/Spline/Decurve/Ltype gen/Undo]:
prompt.
5. The macro then uses a semicolon, which is used to specify pressing Enter at
the end of a menu macro. This ends the command.
Customizing Tool Palettes
Tool palettes give you quick access to blocks and hatches. I cover tool palettes in
Chapter 26. Some customization can be accomplished on the tool palettes them-
selves. Here I explain the procedure for customizing the tool palettes using the
Customize dialog box.
To customize tool palettes, choose Tools ➪ Customize➪ Tool Palettes to display the
Tool Palettes tab of the Customize dialog box, shown in Figure 29-13. The current
tool palettes are listed. Remember that each tab on the Tool Palette window is con-
sidered a separate tool palette.
Use the Customize dialog box to customize tool palettes as follows:
✦ Change the order of the tool palette tabs: Select one of the tabs in the Tool
Palettes list and click Up or Down. This action moves the tab up or down one
and also changes the tab’s order in the dialog box listing. Continue to click Up
or Down until the tab is in the desired position. You can also move the tabs
directly on the Tool Palette by right-clicking the tab name and choosing Move

Up or Move Down.
✦ Create a new tool palette: Click New. In the New Tool Palette dialog box, enter
a name and click OK. To create a new tool palette on the palette itself, right-
click anywhere on the palette and choose Create New Tool Palette.
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1027
1028
Part VI ✦ Customizing AutoCAD
✦ Rename a tool palette: Click Rename. In the Rename Tool Palette dialog box,
enter a new name and click OK. To rename a tool palette on the palette itself,
right-click on the tab’s name and choose Rename Tool Palette.
✦ Delete a tool palette: Click Delete. In the Confirm Tool Palette Deletion dialog
box, which warns you that deletion is permanent unless you first export the
tool palette, click OK to delete the tool palette. You can also right-click any
tool palette and choose Delete Tool Palette.
✦ Import a tool palette: Click Import. In the Import Tool Palette dialog box,
locate the
.xtp file and click Open.
✦ Export a tool palette: Click Export. In the Export Tool Palette dialog box,
choose the location for the file. You can change the name if you want. The tool
palette is saved as an
.xtp file. Click Save.
Figure 29-13: The Tool Palettes
tab of the Customize dialog box
Summary
In this chapter, I covered the basics of customizing AutoCAD. You started to cus-
tomize AutoCAD by:
✦ Creating command shortcuts (aliases) in the
acad.pgp file
✦ Creating your own toolbars that can contain any command sequence you
need.

✦ Working with tool palettes, a new feature of AutoCAD 2004, including changing
their order, renaming and deleting them, and also saving them as a file so that
you can share them with others.
In the next, chapter you read how to create macros with script files.
✦✦✦
36 539922 Ch29.qxd 5/2/03 9:42 AM Page 1028
Creating Macros
and Slide Shows
with Script Files
S
cript files are like macros that you create in your word
processor or spreadsheet. They execute a series of com-
mands automatically. You can use script files to automate
plotting, set up a drawing, clean up a drawing, create a slide
show, or do any repetitive task.
Creating Macros with Script Files
To create a script file, you need to think out the commands
that you want to execute and their options and prompts. Then
you create the text for the script file. Script files have the fol-
lowing characteristics:
✦ They must use the
.scr file name extension.
✦ They are text-only (ASCII) files.
✦ They must use command-line syntax only.
One of the most common uses for script files before
Release 14 was to automate plotting of several drawings at
once. The Batch Plot Utility, introduced with Release 14,
can do many multiple plotting tasks for you.
Creating the script file
You can create the script file using a text editor, such as

Notepad. For early practice with script files, type each com-
mand on its own line. A blank space is equivalent to pressing
Enter. End each line by pressing Enter (also called Return),
without extra blank spaces. If you need two returns one after
another at the end of a line, use a blank line for the second
Note
30
30
CHAPTER
✦✦✦✦
In This Chapter
Automating
commands with
script files
Creating slide shows
Creating slide
libraries for menu
customization
✦✦✦✦
37 539922 Ch30.qxd 5/2/03 9:43 AM Page 1029
1030
Part VI ✦ Customizing AutoCAD
return. Every space is meaningful — getting those spaces and blank lines right is
probably the hardest part of creating a script file. One technique is to start your
script files in a word processing program that can display with nonprinting charac-
ters (blank spaces and returns). You can either save the script file in text format or
copy it into Notepad. Following are some tips to help you create successful script
files with the least aggravation:
✦ Go through the steps once using the command line only before creating the
script file.

✦ If you will use any dialog boxes that ask for files, set the system variable FILE-
DIA to zero (off) before experimenting with the commands you will use in the
script file. This lets you practice the keystrokes without opening dialog boxes.
Or you can practice using the version of the command with the hyphen in
front of it (such as -layer); in most cases, you don’t need the hyphen in the
script file itself.
AutoCAD automatically runs script files as if FILEDIA were off, even if it is set to 1 (on).
✦ For commands that require inputting text such as layer or file names, enclose
the names in quotation marks and for the next use of Enter, press Enter and
go to the next line in the script instead of using a space. Otherwise, AutoCAD
may misinterpret a space as a space in the layer or file name, rather than an
Enter.
✦ Place comments in your script file to explain what you are doing. A comment
is any line that starts with a semicolon.
✦ Keep Notepad open as you work. When you have completed a set of
keystrokes that you want, open the AutoCAD Text Window (press F2), select
the command string you want, right-click, choose Copy, switch back to
Notepad, and paste. Then cut out all the prompts, leaving only the keyboard
entry. You will probably have to readjust the spaces between the words.
✦ You can press End to check for blank spaces at the end of a line. Pressing
Ctrl+End moves the cursor to the end of the document — useful for checking
for extra spaces and lines at the end of a script.
Remember, you can open Notepad from within AutoCAD by typing Notepad at the
command line. At the
File to edit: prompt, press Enter to open a new file. The
acad.pgp file includes this Windows command by default. See Chapter 29 for
details on the
acad.pgp file.
Another option is to simply write down what you type at the command line. As you
write, use an underscore to represent each space. It’s very hard to remember that

you left three spaces between two words unless you see three underscores. Of
course, when you create the script file, you must use spaces, not underscores.
Note
37 539922 Ch30.qxd 5/2/03 9:43 AM Page 1030
1031
Chapter 30 ✦ Creating Macros and Slide Shows with Script Files
As soon as you complete the script file, save it with any name that is meaningful to
you plus an extension of
.scr.
Here’s an example of a script file that draws a series of circles:
circle 2,2 1.5
circle 6,2 1.5
circle 10,2 1.5
circle 14,2 1.5
This script file starts the CIRCLE command, specifies a center point, and specifies a
radius four times. The results are shown in Figure 30-1.
Figure 30-1: Running a script file created this drawing
Running script files
You can run a script file from within a drawing. Use this technique when you want
the script to apply only to that drawing. However, you can also start a script within a
drawing, then close the drawing and continue on to open and process other drawings.
You can also run a script file when loading AutoCAD. You would do this when you
want the script file to apply to more than one drawing. For example, you could use
script files in the following situations:
✦ You want to use a script file to set up every drawing you open. Although the
script file applies to only one drawing at a time, you use it on a different draw-
ing each time.
✦ You want to use a script file to clean up a list of drawings in one batch —such
as thawing all layers on all the drawings in a folder.
Running a script file from within a drawing

To run a script from within a drawing, follow these steps:
1. Choose Tools ➪ Run Script. This opens the Select Script File dialog box, as
shown in Figure 30-2.
37 539922 Ch30.qxd 5/2/03 9:43 AM Page 1031
1032
Part VI ✦ Customizing AutoCAD
Figure 30-2: The Select Script File dialog box
2. Choose the script file you want.
3. Click Open. AutoCAD runs the script file.
Running a script when loading AutoCAD
Run a script when loading AutoCAD by changing the target expression that
Windows uses to open AutoCAD. The easiest way to do this is to use the shortcut
to AutoCAD on your desktop and modify the target there. Right-click the AutoCAD
shortcut and choose Properties. Click the Shortcut tab, shown in Figure 30-3.
Figure 30-3: The Shortcut tab of the
AutoCAD 2004 Properties dialog box
37 539922 Ch30.qxd 5/2/03 9:43 AM Page 1032
1033
Chapter 30 ✦ Creating Macros and Slide Shows with Script Files
The Target text box displays the command expression that Windows uses to open
AutoCAD. Don’t make any change to the current expression — just add to it. The
format for starting a script file is:
drive:\path\acad.exe drive:\path\drawingname.dwg /b script_file
For example, if your current target reads C:\Program Files\AutoCAD
2004\acad.exe
and you want to open a drawing named ba-349.dwg in c:\draw-
ings
and run a script file named pre-plot.scr, your target should read:
“C:\Program Files\AutoCAD 2004\acad.exe” c:\drawings\ba-349.dwg
/b pre-plot

You don’t need to add the .scr extension after the script file name. Long file names
that contain spaces must be enclosed in quotation marks —both in the target and in
the script file itself. You need to include the full path of the drawing. If the script file
is not in AutoCAD’s support file search path, include the entire path. For example:
“C:\Program Files\AutoCAD 2004\acad.exe” “c:\aec\drc\Dobbs
Ferry Apts.dwg” /b c:\aec\drc\cleanup
If you want to start a new drawing, you might want to specify a template. In the pre-
ceding format, replace the AutoCAD drawing file name with:
/t template_name
When you have finished typing your additions in the Target text box, click OK. Now,
when you start AutoCAD, the drawing or template opens, and the script starts.
From within a script file, you can open (and close) other drawings. In this way you
can run a script file on as many drawings as you want. Figure 30-4 shows a script
file,
multi-cleanup.scr, which is used when loading AutoCAD. The target is set
so that AutoCAD opens
Apt 1A.dwg.
Figure 30-4: A script file that cleans
up three drawings
37 539922 Ch30.qxd 5/2/03 9:43 AM Page 1033
1034
Part VI ✦ Customizing AutoCAD
Don’t forget that you can open multiple drawings within the same session of
AutoCAD. You may need to set the SDI (single document interface) system vari-
able to 1, if you plan to use older script files. Otherwise, use the new CLOSE com-
mand to close each drawing after your script file has finished working on it.
Without one of these methods, you may end up with 100 drawings open at
once —and probably a major computer crash as well!
Here’s how multi-cleanup.scr works:
1. The CHPROP command selects all objects and sets their color to BYLAYER.

2. The LAYER command freezes the layer named no-plot.
3. The script file saves the drawing.
4. The script file closes the drawing and opens the next drawing.
5. This process is repeated until the last drawing is edited and saved. The last
drawing is left open.
It’s nice to leave the last drawing open so that when you return to see the results,
you can see that the last drawing has been properly edited. You then feel pretty
sure that all the previous drawings were similarly edited.
Notice the quotation marks around the file names in the script file. These are neces-
sary because the drawing file names include spaces.
In the following exercise you practice creating and using a script file similar to the
multi-cleanup script file used in the previous example, but for only one drawing.
The drawing used in the following Step-by-Step exercise on creating and using a
script file, ab30-a.dwg, is in the Drawings folder of the AutoCAD 2004 Bible
CD-ROM.
Step-by-Step: Creating and Using a Script File
1. Open ab30-a.dwg from the CD-ROM.
2. Save the file as
ab30-01.dwg in your AutoCAD Bible folder.
3. Type notepad ↵. At the
File to edit: prompt, press Enter to open a new
file.
4. Type the following, replacing the underscores with spaces. Note that there
should be two spaces between
all and c in the second line. Press Enter after
the
qsave line.
chprop_all__c_bylayer
-layer_f_no-plot
qsave

5. Save the file as cleanup.scr in your AutoCAD Bible folder. Close Notepad.
On the
CD-ROM
Tip
Note
37 539922 Ch30.qxd 5/2/03 9:43 AM Page 1034
1035
Chapter 30 ✦ Creating Macros and Slide Shows with Script Files
The script file changes the color property of all objects to ByLayer and
freezes the no-plot layer. Notice that the drawing has some text that has been
set to a blue color (maybe to make it more readable). The title block is on the
no-plot layer.
6. Choose Tools ➪ Run Script.
7. In the Select Script File dialog box, find
cleanup.scr in your AutoCAD Bible
folder and click Open. AutoCAD runs the script, changing the text’s color to
ByLayer (green) and freezing the no-plot layer. It also saves the drawing.
If the script file doesn’t work, press F2 to open the Text Window and see
where it got hung up. This will help you see where to correct the script file.
Reopen it (on the Windows task bar choose Start ➪ Documents or Start ➪
My Recent Documents (depending on your version of Windows) and choose
cleanup.scr) and make the correction. Save the file, close it, and try again.
8. Save your drawing.
Taking script files to the max
What if you want to execute that multi-cleanup script file on 200 drawings? Typing in all
those file names would take so long you would wonder if you were saving any time.
You can save time. First, you need to find a text editor or word processor that can create ver-
tical blocks of text. This means that you can select columns of text rather than lines of text.
You can do this in Microsoft Word by holding down Alt and dragging down the text. (Using a
fixed-width font, such as “Courier New” makes selecting columns of text easier.) Then, you

need to format the script file so that the entire set of commands is in one row, as in the figure
shown here. In Microsoft Word, you can use Page Setup to set the paper to landscape and
make it as wide as you need so that the text doesn’t wrap. (Of course, you type the script
once, and then copy the line and paste it as many times as you need.) You do this so that all
the file names will be in one column. Here you see the path but no file name at the end of
each line. The file name will be inserted before the quotation mark at the end of each line.
Now, open a DOS window. (From the Windows task bar, choose Start ➪ProgramsAccessories ➪
Command Prompt.) Use the DOS
cd command to navigate to the folder where all your draw-
ings are. (They should all be in one folder.) Type dir *.dwg /b >dwglst.txt and press Enter.
This creates a listing of all the files in that folder and places it in a text file named
dwglst.txt.
The
/b parameter creates a file that contains only the names of the drawings.
Open the file in a text editor or word processor that can create vertical blocks. Create a ver-
tical block over the drawing names and copy it to the clipboard.
Continued
37 539922 Ch30.qxd 5/2/03 9:43 AM Page 1035
1036
Part VI ✦ Customizing AutoCAD
Creating Slide Shows
One common use for script files is to create a slide show. AutoCAD enables you to
save a view of a drawing as a slide. You can then create a slide library from the
slides and show the slides one after another automatically.
You can save any drawing as an image file and import it into a presentation pro-
gram that creates slide shows, such as Microsoft PowerPoint, Lotus Freelance
Graphics, or Corel Presentations. You can add text, special effects, and more to cre-
ate a professional slide show. For more information, see “Saving rendered images”
in Chapter 25 and “Exporting to other file formats” in Chapter 27.
Creating slides

Creating a slide is like capturing the screen of your drawing. AutoCAD makes a sim-
plified vector file from the current viewport in model space, or from all viewports in
paper space layouts. You can also create a slide of a wireframe, or hidden display.
Unfortunately, you cannot make slides of shaded or rendered displays.
To create a slide, follow these steps:
1. Display the view of the drawing that you want to save as a slide.
2. Type mslide ↵.
3. In the Create Slide File dialog box, choose a location and name for the slide.
Its extension will automatically be
.sld.
4. Choose Save.
Tip
Continued
Open the script file in the same text editor or word processor, place the cursor at the top-
left corner of the vertical block, and paste. You should get all the drawing names inserted in
the right place, as shown here with two drawings. If you’re in a word processor, don’t forget
to save the file as a Text Only document.
Used in this way, script files can be an extremely powerful tool for editing large numbers of
drawings in one batch.
37 539922 Ch30.qxd 5/2/03 9:43 AM Page 1036
1037
Chapter 30 ✦ Creating Macros and Slide Shows with Script Files
Viewing slides
To view a slide, follow these steps:
1. Type vslide ↵.
2. In the Select Slide File dialog box, choose the slide you want to view.
3. Choose Open. AutoCAD displays the slide.
Do a Redraw to return to your drawing. You cannot draw in or edit a slide.
The drawing used in the following Step-by-Step exercise on creating and using a
script file, ab30-b.dwg, is in the Drawings folder of the AutoCAD 2004 Bible

CD-ROM.
Step-by-Step: Creating and Viewing Slides
1. Open ab30-b.dwg from the CD-ROM.
2. Save the file as
ab30-02.dwg in your AutoCAD Bible folder.
3. Type hide ↵. AutoCAD hides the drawing.
4. Type mslide ↵. In the Create Slide File dialog box, click the Save in drop-down
box and select your
AutoCAD Bible folder, if it isn’t already selected. In the
File name text box, change the name from its default of
ab30-02.sld to
ab30-02a.sld. Click Save.
5. Choose View ➪ 3D Orbit from the Standard toolbar. Click and drag the right
quadrant circle of the arcball slightly to the left. Press Esc.
6. Issue the MSLIDE command again. This time save the slide as
ab30-02b.sld.
7. Choose 3D Orbit from the Standard toolbar. Again, click and drag the right
quadrant circle of the arcball slightly to the left. Press Esc.
8. Issue the MSLIDE command again and save the slide as
ab30-02c.sld.
9. Click Zoom Previous on the Standard toolbar until you see the message
No
previous view saved.
10. Type vslide ↵. In the Select Slide File dialog box, choose the first slide,
ab30-02a.sld. Click Open. AutoCAD displays the slide.
11. Repeat the VSLIDE command and display
ab30-2b.sld. Do the same with
ab30-02c.sld.
12. Click Redraw All on the Standard toolbar.
13. Save your drawing.

On the
CD-ROM
37 539922 Ch30.qxd 5/2/03 9:43 AM Page 1037
1038
Part VI ✦ Customizing AutoCAD
Using scripts to create slide shows
You can create a script file that displays slides one after another, resulting in a slide
show. AutoCAD provides two special script file commands for this purpose:
✦ DELAY nnnn pauses the script for the number of milliseconds you specify. For
example, DELAY 3000 pauses the script for three seconds.
✦ RSCRIPT repeats the script from the beginning. Use this command to create a
continuously running script. To stop the script (whether repeating or not),
press Esc or backspace, or drop down any menu.
✦ RESUME restarts a script file after you have stopped it.
The VSLIDE command, which displays a slide, can also be used to preload the next
slide into memory. You use this command to preload a slide while viewers are look-
ing at the previous slide. This reduces the waiting time between slides. To use this
feature, put an asterisk (*) before the file name in the VSLIDE command. The next
VSLIDE command detects that a slide has been preloaded and displays it without
asking for the slide name. Here’s how it works:
vslide ab30-2a
vslide *ab30-2b
delay 3000
vslide
vslide *ab30-2c
delay 3000
vslide
rscript
This script file does the following:
1. It displays

ab30-02a.sld.
2. It preloads
ab30-02b.sld.
3. It waits three seconds, displaying
ab30-02a.sld.
4. It displays
ab30-02b.sld.
5. It preloads
ab30-02c.sld.
6. It waits three seconds, displaying
ab30-02b.sld.
7. It displays
ab30-02c.sld.
8. It repeats the script from the beginning.
Step-by-Step: Creating a Slide Show
1. Open Notepad and type the following script:
vslide ab30-02a
vslide *ab30-02b
delay 3000
37 539922 Ch30.qxd 5/2/03 9:43 AM Page 1038

×