Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Autocad 2005 And Autocad LT 2005 Bible (2004).pdf
Скачиваний:
92
Добавлен:
17.08.2013
Размер:
32.22 Mб
Скачать

Chapter 29 Customizing Commands, Toolbars, and Tool Palettes

907

3.The menu loads and the command line displays the message Menu loaded successfully. MENUGROUP: ACAD or ACLT. Click Close. Your new toolbars and buttons disappear.

Reloading acad.mnu or aclt.mnu would remove any partial menus that you may have loaded. If you had loaded the Express Tools (AutoCAD only), they will also disappear. Enter expresstools on the command line to reload Express Tools. For more information, see my coverage of menu files in more detail in Chapter 33.

Customizing Tool Palettes

Tool palettes give you quick access to blocks, hatches, and commands. I cover tool palettes in Chapter 26. Some customization can be accomplished on the tool palettes themselves. 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-11. The current tool palettes are listed. Remember that each tab on the Tool Palette window is considered a separate tool palette.

Figure 29-11: The Tool Palettes tab of the Customize dialog box.

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 drag it up or down. 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: Right-click and choose New Tool Palette. Enter a name and press Enter. To create a new tool palette on the palette itself, right-click anywhere on the palette and choose New Tool Palette.

908 Part VI Customizing AutoCAD

Rename a tool palette: Click the palette’s name to select it and then click it again so that you see a border around the name. Enter a new name and press Enter. 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: Select the tool palette, right-click and choose 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 rightclick any tool palette and choose Delete Tool Palette.

Import a tool palette: Right-click and choose Import. In the Import Tool Palette dialog box, locate the XTP file and click Open.

Export a tool palette: Right-click and choose 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.

Organize tool palettes into groups: In the Palette Groups area, right-click and choose New Group. Enter a name for the group and press Enter. From the Tool Palettes list on the left side of the dialog box, drag one or more tool palettes under the group name on the right, as you see in Figure 29-11.

Summary

In this chapter, I covered the basics of customizing AutoCAD and AutoCAD LT. You started to customize by:

Creating command shortcuts (aliases) in the acad.pgp or aclt.pgp file

Creating your own toolbars that can contain any command sequence you need

Working with tool palettes, including changing their order, renaming and deleting them, and saving them as a file so that you can share them with others

In the next chapter, you read about how to create macros with script files.

 

 

 

Creating Macros and Slide Shows with Script Files

Script files are like macros that you create in your word processor or spreadsheet. They automatically execute a series of commands.

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 following characteristics:

They must use the .scr filename extension.

They are text-only (ASCII) files.

They must use command-line syntax only.

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 command 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 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 nonprinting characters (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:

Before creating the script file, go through the steps once using the command line only.

If you’ll use any dialog boxes that ask for files, set the system variable FILEDIA to zero (off) before experimenting with the commands you’ll use in the script file. This lets you practice the

30C H A P T E R

In This Chapter

Automating commands with script files

Creating slide shows

Creating slide libraries for menu customization

910 Part VI Customizing AutoCAD

 

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.

Note

Script files automatically run as if FILEDIA were off, even if it’s set to 1 (on).

For commands that require inputting text such as layer names or filenames, 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 name or filename, rather than an Enter.

Place comments in your script file to explain what you’re doing. A comment is any line that starts with a semicolon.

Keep Notepad open as you work. When you’ve 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’ll 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 — this is 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. (In AutoCAD LT, you need to start Notepad from Windows.)

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.

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.

Chapter 30 Creating Macros and Slide Shows with Script Files

911

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 run the same script for other drawings.

You can also run a script file when loading AutoCAD or AutoCAD LT. 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 drawing 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

If you want the script to apply only to the current drawing, start the script from within your 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.

2.Choose the script file you want.

3.Click Open. AutoCAD or AutoCAD LT runs the script file.

Running a script when loading AutoCAD or AutoCAD LT

To run a script when loading AutoCAD or AutoCAD LT, change the target expression that Windows uses to open AutoCAD or AutoCAD LT. The easiest way to do this is to use the shortcut to AutoCAD or AutoCAD LT on your desktop and modify the target there. Right-click the AutoCAD or AutoCAD LT shortcut and choose Properties. Click the Shortcut tab, shown in Figure 30-2.

Figure 30-2: The Shortcut tab of the AutoCAD 2005 Properties dialog box.

912 Part VI Customizing AutoCAD

Taking script files to the max

What if you want to execute that multi-cleanup script file on 200 drawings? Typing in all those filenames 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 vertical 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 filenames will be in one column. Here you see the path but no filename at the end of each line. The filename 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 Programs Accessories Command Prompt.) Use the DOS cd command to navigate to the folder where all your drawings 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 vertical block over the drawing names and copy it to the Clipboard.

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.

The Target text box displays the command expression that Windows uses to open AutoCAD or AutoCAD LT. Don’t make any change to the current expression — just add to it. If you’re using AutoCAD LT, just substitute aclt.exe for acad.exe and your AutoCAD LT program location in the following examples. The format for starting a script file is:

drive:\path\acad.exe drive:\path\drawingname.dwg /b script_file

Chapter 30 Creating Macros and Slide Shows with Script Files

913

For example, if your current target reads C:\Program Files\AutoCAD 2005\acad.exe and you want to open a drawing named ba-349.dwg in c:\drawings and run a script file named pre-plot.scr, your target should read:

“C:\Program Files\AutoCAD 2005\acad.exe” c:\drawings\ba-349.dwg /b pre-plot

You don’t need to add the .scr extension after the script filename. Long filenames 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 the support-file search path, include the entire path. For example:

“C:\Program Files\AutoCAD 2005\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 preceding format, replace the drawing filename with:

/t template_name

When you’ve finished typing your additions in the Target text box, click OK. Now, when you start AutoCAD or AutoCAD LT, 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-3 shows a script file, multicleanup.scr, which is used when loading AutoCAD or AutoCAD LT. The target is set to

Apt 1A.dwg.

Figure 30-3: A script file that cleans up three drawings.

Note 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 variable to 1, if you plan to use older script files. Otherwise, use the CLOSE command 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.

914 Part VI Customizing AutoCAD

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.

Tip

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 filenames in the script file. These are necessary because the drawing filenames include spaces.

In the following exercise, you practice creating and using a script file similar to the multicleanup script file used in the previous example, but for only one drawing.

On the

The drawing used in the following Step-by-Step exercise on creating and using a script file,

CD-ROM

ab30-a.dwg, is in the Drawings folder on the 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.In Windows, choose Start Run. Type notepad and click OK.

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. 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. The script runs, 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.