You are on page 1of 5

Script Files (.SCR) Script files are simply a list of commands that are run as a group.

A script file does not have the ability to stop and wait for user input. Many AutoCAD commands bring up special dialog boxes to assist the user in the setting of system variables and in running the specific command. When running a script, these dialog boxes are not used, as the script cannot pause for user input. Therefore, a command line menu is used when running a script file and the user must become familiar with this method of command input. AutoCAD is interactive, therefore the user can experiment with commands in the command line and place them in scripts, or create an iterative script, which is one that is developed and tested as it progresses from concept to completion. A sample script file is displayed below: DRF271.SCR snap .125 grid .5 layer make vports color blue vports zoom all | This script sets the SNAP to .125 and the GRID to .5 It then creates a new layer called vports and sets the vports layer color to blue Finally it does a ZOOM to place everything in the drawing on the screen Notice the blank line following the LAYER command. The blank line is required, as the LAYER command calls up a dialog box that is interactive with the user. Because you cannot pause a script for user input, the dialog box is not displayed and the LAYER command line menu is used instead. You can work in the LAYER command to create and set layers active, change their colors and linetypes, as well as turn layers on or off. Until you are finished working with the LAYER command, you will still be in the layer command line menu and you must hit an extra ENTER key to exit the command. Here are some things to remember. Whenever you press the space bar in AutoCAD it is the same as an ENTER key. Pressing the ENTER key executes the previous command. Some commands will require an extra ENTER after you are finished with the command. A script will not pause for user input. The command line menu can be used to iteratively create the script. This is how I go about creating a script command file. 1. I determine what it is I want to accomplish by the script and roughly the commands I will use 2. I open AutoCAD and type in the commands I want to use to see if any of them will bring up a dialog box and require extra care in the development of the script command. 3. I write down exactly what I type in so as to record what needs to go into the script command. This includes spaces, ENTER keys, etc. 4. I create a test script where I can experiment with commands to see how I need to write them so they will do exactly what I want them to do and I know how the AutoCAD command will behave in a script file. 5. I add the proven script command to my working script command file and test it again to make sure that nothing happens that I dont expect. 6. I then begin working on and testing the next AutoCAD command I want to use.

I follow this procedure for most of my script file development. Lets now go through a sample procedure to find out what the LAYER command does in a script file. To begin, make sure that AutoCAD is open and at the command line type NOTEPAD You will be asked to enter a file name to edit and key in TEST.SCR As the file is new, AutoCAD will ask if you want to create it, accept it and you will see a new window for the notepad with your file TEST.SCR open. Type LAYER followed by a space (do not press ENTER) and save the file in your C:\DRF271 or Z:\DRF271 folder so you will be able to find it again. It is important that the only characters in the file so far are the 5 letters making up the word layer and the space following the word. Throughout this course we will be having multiple windows open at the same time. To change between windows, simply click in the program name at the bottom of the screen. Again, to switch between AutoCAD and your test.scr file, do not close them or you will need to re-open them each time you want to access them, but simply click on the program name at the bottom of your screen. For the purposes of this course, I will be displaying the contents of the script files in the following manner, I have also placed a bar to represent where the cursor should be: TEST.SCR layer |

Now we need to try our test.scr file and see what happens. Type SCRIPT at the Command prompt. A dialog box will open asking you for the script file to run. Find your DRF271 folder and the test.scr file should be displayed. (In the event the test.scr file is not located in this directory, you may find it in your My Documents folder. Move or copy the file to your DRF271 folder.) Select your test.scr file and press OPEN

AutoCAD will execute the script file commands as you have entered them in the script file. Notice that there is a menu in the command area that may be new to you. This is the LAYER command line menu. It is from this option menu that we will be creating the layer command in our script file. First we want to create several new layers. This will use the New option. (If we were only creating one new layer, we could use the Make option. This results in a combination of the New and Set commands. It creates the new layer and sets the new layer as the current layer.) Click on the test.scr tab at the bottom of your screen and after the space following the word layer, type in new, followed by a space, and then the names of the new layers you want. Here we can enter several new layers at the same time. We will create the following layers: vports, dim, center, hidden. When you type in a list of new layer names, separate them with commas, but dont put a space after the comma, just continue with the list of names. You will need to put a space after the word hidden but dont press the ENTER key, and save the test.scr file. TEST.SCR layer new vports,dim,center,hidden |

Try it out! Go to AutoCAD and since you may still be in the LAYER command, press ESC a couple of times. Type SCRIPT at the Command prompt, select your test.scr file and see what happens. You may need to press the ESC key to get out of the LAYER command after you run the script. We have not finished working with the layer command yet and the extra ENTER key has not been put into your script file. Look in your list of layers and you should see the new layers displayed. We will now change the color and linetypes of several of the layers. Before we do this, we need to UNDO everything in our AutoCAD drawing so we are sure of what is happening when we run the script file again. Enter U at the Command prompt until you get the message Everything has been undone and Nothing to undo. Now run the test.scr file again, but this time, dont exit out of the LAYER command. Type in color and press ENTER to begin setting the color of the layers you just created. You will be asked for the new color followed by the layer you want to be that new color. We will be setting the dim layer to green.

We will be setting the center layer to cyan, and the hidden layer to color 42. TEST.SCR layer new vports,dim,center,hidden color green dim color cyan center color 42 hidden |

Save the test.scr file and try it out. (Remember to UNDO everything in AutoCAD before you run the script.) Look to see that the colors are properly assigned. UNDO everything in your AutoCAD file before we proceed. We will now set the line types for the center and hidden layers. In the LAYER command we can load linetypes into the drawing at the same time we set a layer to that linetype. We will also be running out of room on the current line in our test.scr file. At the end of the first line, do not put a space after the word hidden, or delete the space if you have one, and press the ENTER key to start a new line in the script file. TEST.SCR layer new vports,dim,center,hidden color green dim color cyan center color 42 hidden ltype center center ltype hidden hidden |

You should have the general idea down by now. Lets finish up the LAYER command by setting the vports layer so it does not plot, and the line weight of the hidden and center lines to .05mm. TEST.SCR layer new vports,dim,center,hidden color green dim color cyan center color 42 hidden ltype center center ltype hidden hidden plot n vports lweight .05 center,hidden snap .125 | Remember at the end of a line you do not put a space after the command. This time, however, do place an extra ENTER command to exit completely out of the LAYER command line menu. I have added another command at the end of the script file to emphasize the need to have the extra blank line. The command I have added is the snap command to set the snap to .125 followed by pressing ENTER to place the cursor on the next line of the test.scr file. Open your Layer Properties Manager to see what changes you have made. You need to put the working command into the script file that you will be turning in. Copy all of the information from your test.scr file and open a new file called DRF271.SCR and save the layer command information into it.

Now open your test.scr file again and erase the command information in it to give you a clean test file to use. Continue working on commands until you have the necessary number of commands for the assignment. Your assignment is to create a script file that runs at least 12 separate AutoCAD commands (you may use a command multiple times, but it only counts as one command). Test your final DRF271.SCR script file really well to make sure it all works, and submit it to the instructor. You can use the script when you start a new drawing so all of your preferred settings can be adjusted. You can put virtually any command into a script file that does not pause the system and require specific input from the user. If you are having trouble coming up with ideas for commands to use, I have listed some that students seem to like to use. Some of the commands may be new to you. In that case, go to the AutoCAD help screens to see what they do, and determine if you can use them. MSLIDE VSLIDE DELAY (creates a screen image of the AutoCAD drawing edit window) (displays of shows a previously saved image in the drawing edit window) (allows a script file to pause for a specified time to display a slide)

You may also set any of the system variables we discussed in an earlier unit into a script file: CLAYER (current layer, used to change the current layer) CELTYPE (current element linetype, used to set the linetype of a the next elements created) FILLETRAD (fillet radius, used to set the fillet radius in the fillet command) etc.

You might also like