Las Vegas, Nevada

Speaker: Course:

Las Vegas, Nevada

November 27-30, 2001

Daniel Abbott Southern Maine Technical College South Portland, ME 04106 abbott@ 207 767-9564

Super Scripting Secrets PR42-3 Friday 9:30 pm to 11:00 pm

Course Description:

A script automatically executes a series of commands that are contained in a text file. It can be used to do any number of things, including creating a drawing, changing layer and variable settings for an existing drawing, automatically extracting block attributes, creating slides, running a slide show, starting AutoCAD with a particular drawing, or editing an unlimited number of drawing files while you do something else. A script file is a very simple, yet potentially very powerful, customizing tool. We will also briefly explore Script Pro and the benefits that it has to offer the users of AutoCAD 2000, 2000i and 2002.

1

SUPER SCRIPTING SECRETS

If you can use AutoCAD and can type, than you can write script files. The script file is AutoCAD's version of a batch file. A script file is an ASCII text file with an extension of .SCR. It can be created in any word processor or text editor, but there are some very good reasons to use a text editor. The choices are Notepad, WordPad or Edit (a DOS text editor).

A script automatically executes a series of commands that are contained in a text file, as long as it has an .SCR extension. It can be used to do any number of things, including: creating a drawing; changing layer and variable settings for an existing drawing; changing setting in the system registry; automatically extracting block attributes; creating slides; running a slide show; starting AutoCAD with a particular drawing; or editing an unlimited number of drawing files while you do something else. A script file is a very simple, yet potentially very powerful, customizing tool.

Creating and using a script file requires the following steps: 1. Start WordPad and type a list of AutoCAD commands just as you would at the keyboard. You can place one command on each line, or separate commands with spaces. You have to be careful not to have any extra spaces between commands or at the ends of lines. A space in a script has the same effect as pressing the ENTER key. 2. Save the file with a filename and an extension of .SCR. This is critical. Without the .SCR extension, AutoCAD won't recognize a text file as a script when you try to run it. 3. Have AutoCAD run the script. This simply requires that you issue the SCRIPT command. You can do this from the keyboard by typing either SCRIPT or SCR, or by selecting from the Tools menu.

2

However you issue the command, the result will be a file management dialog box (as long as the variable FILEDIA is set to 1, which is the default). Note that there is only one file type listed in the drop down window. That is why it is critical that you save the script file with an extension of .SCR. By default, AutoCAD is looking for a script with the same name as the drawing on which you are working. Normally you will have named your script something other than the name of the drawing.

SIMPLE SCRIPT FILE

To get a sense of how a script works, create a text file named LAYER.SCR and type the following lines. Be careful not to create extra lines or spaces anywhere in the file. There are two spaces after the last line to execute the last color option and to exit the LAYER command.

Layer new fl1,fl1-dim,fl1-txt color 2 fl1 color 3 fl1-dim color 4 fl1-txt

You can also type the script file on one line, with a single space between each of the commands. The same setup script would look like this:

Layer new fl1,fl1-dim,fl1-txt color 2 fl1 color 3 fl1-dim color 4 fl1-txt

Save the file with the extension .SCR (You may have to place the entire file name and extension in quotes to avoid a double extension). In AutoCAD issue the SCRIPT command. Use the file dialog box to locate the file you just created. Three new layer names will be created with colors set to 2, 3, and 4.

3

You might wonder why the Layer Properties Management dialog box did not appear when you ran this script file. Some commands work differently in a script than they do when typed at the keyboard. Since a script cannot be paused, a dialog box would cause it to stop. The layer command in a script is the command line version you get if you type ?LAYER, with the dash in front of the command name.

You can place any AutoCAD command into a script. That means you could expand the SETUP.SCR script to automatically setup a particular kind of drawing by also setting limits, units, particular variables, etc. Although you can accomplish the much of this for a new drawing by creating a template drawing, an existing drawing might need to be setup after it has been created when it is too late to use a template. This is particularly true if you are working with drawings from other offices, which do not follow your standards. There are many variables that are saved in the system registry, not the drawing file, so a template cannot control them. There are also some other things that you can do with a script that you just can't conveniently do any other way.

CREATING AND VIEWING SLIDES

One very common use of script files is the creation of a slide show. A slide show is a series of still images of AutoCAD drawings. A slide represents what is on the screen when it is created. Creating slides requires two steps:

1. Create the drawing and use ZOOM, 3DORBIT, VPOINT, or DVIEW to establish the views you want. Use the HIDE, SHADE, or SHADEMODE command for slides of 3D objects.

2. Make the slides using the MSLIDE command. Once you have displayed the view that you want, type MSLIDE and, using the file dialog box, give the location and name of the slide file you are creating. A file extension of .SLD is added to the name automatically. The slide will show the image on the screen, even if the image is the result of a hide or a shade command. A slide will NOT capture a rendered image, however.

4

To view a slide, you must use the VSLIDE command. You will get another file dialog box asking you to select a slide file to view. Once you have selected it, the slide fills the screen until you regenerate the drawing. The slide is just an image. Any slide can be viewed while you are in any drawing. The objects in the drawing are still there, your slide is just projected over them.

Slides are like snapshots. They take far less time to view than generating alternative views on a 3-D drawing, or calling up a series of individual drawings. This makes demonstrations to clients much faster. You can also send slide files to others for viewing in AutoCAD, without letting them have the drawing itself, although a .DWF file can be more effective.

USING SCRIPT FILES TO CREATE AND SHOW SLIDES

Creating and showing slides one at a time can be time consuming, particularly for 3D drawings. This is where a script file comes in. You can use a script file to create a series of slides and then use a different script file to show them as a slide show. The procedure for using a script file to create and show slides does not involve a dialog box. Once you have written the script file, the slides are shown automatically.

1. Write the script file. There are only a few commands that are unique to scripts: DELAY -- leaves the image on the screen for a given number of milliseconds; BACKSPACE key ? used to pause a script while it is running; RESUME -- used to resume a script immediately after it is cancelled or paused; RSCRIPT ? placed at the end of a script file, this will cause the script to repeat all the steps preceding it.

2. Run the script. You can do this while editing any drawing. You respond to the prompt by giving the location and name of the script file.

Using a Script for Making the Slides

In order to show a slide show, you must have slides. When you are making slides of a 3D object, that process can be time consuming, especially if the object is a building that must be viewed in perspective using the DVIEW command. The following script will

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download