Navigation
 
AutoCAD Tutorial

AutoCAD 2004 Customization Tutorial: Modifying Objects with Scripts

By Alireza Parsai, June 3, 2003

Scripts are incapable of accepting user input. However, if the modifying commands do not need user input, scripts can be useful. If you are not familiar with script files, please read through the following tutorial:
AutoCAD 2004 Tutorial: Setting Up a Drawing with a Script

In the following tutorial you will write a script for rotating the second hand of a clock.

1. Download R16 - Clock.dwg.

Note: If you are using an earlier release of AutoCAD download R15 - Clock.dwg.

2. Open the drawing in AutoCAD [Figure 1].


Figure 1 - Click on image to enlarge

3. The clock circumference is 360 degrees. Since a full rotation of the second hand is equivalent to 1 minute and every minute is 60 seconds each second is equal to 6 degrees (1 minute = 360 degrees = 60 seconds 6 degrees). The following sequence will rotate the second hand by 1 second:

Command: rotate8  
Current positive angle in UCS:  ANGDIR=counterclockwise  ANGBASE=0
Select objects:
c8  
Specify first corner:
1.5,-1.58  
Specify opposite corner:
-1.5,1.58  
3 found
Select objects:
8  
Specify base point:
0,08  
Specify rotation angle or [Reference]:
-68  

Notes:

► User entries are in bold.

► The 8 means press Enter.

► The crossing selection method is used to select the smallest circle and the lines that build the second hand. Here selecting the small circle is not necessary but harmless.

► The base point for rotation is the base point for circle (here 0,0).

► The rotation angle is negative as it is clockwise.

4. In command line type Notepad and then press enter twice. The Notepad window appears.

5. Type the proper text [Figure 2].


Figure 2

6. Save the file as "clock.scr" in a folder that belongs to AutoCAD file search path.

Note: If you are not familiar with AutoCAD file search path read the following tutorial:

AutoCAD 2004 Customization Tutorial: Search Paths

7. Switch to AutoCAD window.

8. Alter the FILEDIA system variable to 0. This will skip showing dialog boxes when you invoke many of AutoCAD commands including SCRIPT, OPEN, and SAVEAS.

9. Invoke SCRIPT and then enter clock. The second hand rotates 1 second (or rather 6 degrees) clockwise.

Command: scr8
SCRIPT
Enter script file name <>:
clock8

10. To create animation you need to modify the script as shown in figure 3.


Figure 3

Note:

► The "delay 1000" interrupts the script for about 100 milliseconds or rather 1 second.

► The "rscript" repeats the script from the first line.

11. Save the new file.

12. In AutoCAD load the script again.

13. The animation starts. Press Esc to cancel the running script.

14. Alter the FILEDIA system variable to 1.

Click here to download the script file.


About the Author

Alireza Parsai is the founder of cadpanel.com. He is a mechanical engineer with more than 12 years experience with AutoCAD. Alireza is an Autodesk Authorized Author, the AutoCAD consultant for Al Khawarizmi Institute, a contributing editor for Augiworld magazine, a writer for CAD Digest, an instructor for AUGI Training Program, and an elected speaker for Autodesk University 2002. He has written 7 books in Farsi, 3 booklets in English, and more than 30 articles for different magazines and newsletters. You can reach him at alireza.parsai@cadpanel.com or visit his website www.cadpanel.com

More CAD Corner tutorials >>