|
|
||||||||||||
|
New Service
Photorealistic
Renderings
Tips & Tricks
Script files
This issue's topic is one of those things that, on the surface appears to be very complicated. Writing script files, however, is not only simple and time saving - you already know how to do it!
Script files can give you a degree of automation normally associated with programming languages like LISP or VB(A). Script files are not at the same level as true programming languages, as they cannot interact with the user or evaluate conditional expressions. But there is one thing they do very well, and that is to automate data entry.
Writing a script file is no more complex than working in AutoCAD. Nearly everything you could type at the command prompt is valid script syntax. In fact, if you can picture AutoCAD's text screen without all of the interactive prompts displayed by AutoCAD, you are picturing a script file. A script file is simply a text file containing a list of instructions for AutoCAD to carry out. These instructions may be AutoCAD commands, System Variables, add-on commands (loaded from LISP, ARX, VBA, etc.), as well as the data they require. A good way to write a script file is to simply perform the desired actions in AutoCAD using only the command prompt (with no menus or mouse interaction), and write down every step you perform.
For example, here is a script that will draw a 50x100 rectangle starting at the origin: LINE 0,0 50,0 50,100 0,100 c
AutoCAD interprets a space or a new line as <ENTER>. My first example communicated <ENTER> by placing each statement on a new line. The following script would accomplish the same thing, but this time uses spaces for <ENTER>, and also uses relative coordinate entry: LINE 0,0 @50<0 @100<90 @50<180 c
Ok, I realize not many of you spend your days drawing 50x100 rectangles. Let's look at some more practical purposes. I have one script that I wrote over 10 years ago which I still use quite often. Have you ever opened a drawing with settings other than what you prefer? How long does it take you to reset BLIPMODE, PDMODE, MAXSORT, UCSICON and every other pesky little system variable that is set incorrectly? Throw 'em in a script! Here is a clip from my script (Note the use of spaces and new lines to make the file easier to read and edit.): ANGBASE 0
Believe me - this is a very small portion of the file! So how do you use it? It's quite simple. Open Notepad or any other text editor and type away. You could even copy and paste any of the above samples and try it for yourself. When you are done, just save the file with any name and the extension '.scr'. This identifies it as a script file. In AutoCAD, you may type SCRIPT at the command line and navigate to the file, or more conveniently, drag the file's icon into the AutoCAD drawing window and release the mouse button. The script takes over from there.
Ok, there's one practical use of scripts. I'll give you one more idea and then some samples to play with.
At some time, most of us have had an ASCII file containing unformatted point data that we needed to get into AutoCAD. Maybe you wanted point objects placed at each location; maybe you wanted a 3DPOLY to pass thru those points; or maybe you wanted that text to be placed in the drawing. There are many solutions, but none are as simple as script files. Think of it this way: those values in the ASCII file are exactly the same as the coordinates I used in the first example. So all that is missing is the instruction telling AutoCAD what to do with all of those points. Here is a tip: For drawing thru the coordinates (LINE, PLINE, etc.), simply add the command name as the first line of the ASCII file. Then, to terminate the command you will need either an extra <ENTER> (space or new line) to end the figure or a 'C' to close it. For non-repeating commands, such as POINT, you will need to precede the command with the command 'MULTIPLE' (see AutoCAD help for more info). (One tip concerning the MULTIPLE command: Unlike other commands which end when they are done, MULTIPLE stays active until you press <Escape>.)
To help you along your way, I have posted three sample script files to our web server for you to play with. Download them, then execute them in a new drawing file. (Remember? Either use the SCRIPT command or drag and drop the files.) The links appear at the end of this article.
Note: These scripts contain 3D data. Once you have run all three, use the VPOINT command or the Object Viewer to see this.
http://www.customcadsolutions.com/downloads/newsletterfiles/script1.scr http://www.customcadsolutions.com/downloads/newsletterfiles/script2.scr http://www.customcadsolutions.com/downloads/newsletterfiles/script3.scr
For automatic field-to-finish, there is no equal to Topomatic.
About Custom CAD Solutions
View a partial client list:
Subscription Info
Click here to unsubscribe.
Note: Due to a problem with our mail list software, you may receive this email even though you have previously unsubscribed. If this is the case, we apologize for the inconvenience. Please click the above link to unsubscribe and we will again add you to our exclusion list. Thank you for understanding.
This newsletter is published by Custom CAD Solutions. We provide this email newsletter free of charge. We welcome your ideas, questions, suggestions and submissions. Email any comments or information to newsletter@customcadsolutions.com
Copyright © 2003 by Custom CAD Solutions Reproduction or distribution in whole or in part without written permission is prohibited.
|
|||||||||||
|
Copyright 2004 - Custom CAD Solutions |
||||||||||||