CASDLectureNotes_4
CASDLectureNotes_4
A script is a text file with one command on each line. These files are created outside AutoCAD using a
text editor (such as Microsoft® Windows Notepad) or a word processor (such as Microsoft® Word) that
can save the file in ASCII format. The file extension must be .SCR.
Each line of the script file contains a command. Each blank space in a script file is significant: AutoCAD
accepts either a space or ENTER as a command or data field terminator.
A script can execute any command at the Command prompt except a command that displays a dialog
box. AutoCAD provides command line versions of the dialog box commands
Script files can contain comments. Any line that begins with a semicolon (;) is considered a comment, and
AutoCAD ignores it while processing the script file. The last line of the file must be blank.
All references to long file names that contain embedded spaces must be enclosed in double quotes. For
example, to open the drawing my house.dwg from a script, you must use the following syntax:
open "my house"
Script programming was introduced to AutoCAD with version 1.4, back in 1983. A script does one thing
and one thing only: it mimics what I type at the keyboard. Anything we type in AutoCAD that shows up at
the 'Command:' prompt can be put into a script file.
The purpose of the script is to reduce keystrokes by placing the keystrokes in a file. A script file to draw a
line and a circle looks like this:
A limitation to scripts is that only one script file can be loaded into AutoCAD at a time. However, a script
file can call another script file. Or, we can use some other customization facility to load script files with a
single mouse click, such as toolboxes, menu macros, and AutoLISP routines.
Another limitation is that scripts stall when they encounter invalid command syntax.
There are a grand total of four commands that relate specifically to scripts. In fact, these commands are
of absolutely no use for any other purpose. In rough order of importance, these are:
Script
The Script command performs double-duty: (1) it loads a script file; and (2) immediately begins running it.
Use it like this:
Command: script
Enter script file name <C:\CAD\AutoCAD LT 2000i\Drawing1.scr>: filename
Remember to turn off (set to 0) the FileDia system variable, so that the prompts appear at the command
line, instead of the dialog box.
RScript
Short for "repeat script," this command re-runs whatever script is currently loaded in AutoCAD. A great
way to creating an infinite loop. There are no options:
Command: rscript
4.1
COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4
Resume
This command resumes a paused script file. A script file can be paused by pressing the Backspace key.
Again, no options:
Command: resume
Delay number
To create a pause in a script file without human intervention. The number specifies the pause in
milliseconds, where 1,000 milliseconds equal one second. The minimum delay is 1 millisecond; the
maximum is 32767 milliseconds, which is just under 33 seconds. Delay is used in a script file to wait while
a slide file is displayed or to slow down the script file enough for humans to watch the process, like this:
In addition to these four script-specific commands, there are some special characters and keys.
; (semi-colon)
the semi-colon lets us insert comments in a script file. AutoCAD ignores anything following the semi-
colon.
Esc stops a script file dead in its tracks; use the RScript command to start it up again from the beginning
Example 4.1. Set limits to -10,-10 10,10 and draw a line 0,0 0,5
LINE
0,0
0,5
ROTATE L
0,0 -6
DELAY 1000
RSCRIPT
4.2
COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4
A body plan consists of a series of 2D curves representing the ship sections or stations. The coordinates
(offsets) of these sections must be provided as an offset table.
Example 4.3. Let us assume that typical offsets for a section are given as follows
Y Z
0.000 -2.076 station 17
0.380 -2.061
0.702 -2.018
0.971 -1.950
1.191 -1.863
1.367 -1.759
1.503 -1.644
1.605 -1.520
1.674 -1.391
1.710 -1.260
1.715 -1.130
1.690 -1.004
1.635 -0.884
1.554 -0.773
1.342 -0.572
1.115 -0.384
1.017 -0.289
0.937 -0.193
0.876 -0.093
0.796 0.108
0.756 0.308
0.735 0.600
0.755 0.918
0.794 1.168
0.942 1.779
1.352 3.108
1.972 5.129
2.061 5.403
2.317 6.160
;station 17
PLINE
0.000,-2.076
0.380,-2.061
0.702,-2.018
0.971,-1.950
1.191,-1.863
1.367,-1.759
1.503,-1.644
1.605,-1.520
1.674,-1.391
1.710,-1.260
1.715,-1.130
1.690,-1.004
1.635,-0.884
1.554,-0.773
1.342,-0.572
1.115,-0.384
1.017,-0.289
0.937,-0.193
0.876,-0.093
0.796,0.108
0.756,0.308
0.735,0.600
0.755,0.918
0.794,1.168
0.942,1.779
1.352,3.108
1.972,5.129
2.061,5.403
2.317,6.160
4.3
COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4
This script file can be modified to specify the limits of the drawing. The curve fit and line thickness can
also be added as follows (Section1.scr)
;station 17
LIMITS -3,-3 10,10 GRID 10
ZOOM A
PLINE
0.000,-2.076
0.380,-2.061
0.702,-2.018
0.971,-1.950
1.191,-1.863
1.367,-1.759
1.503,-1.644
1.605,-1.520
1.674,-1.391
1.710,-1.260
1.715,-1.130
1.690,-1.004
1.635,-0.884
1.554,-0.773
1.342,-0.572
1.115,-0.384
1.017,-0.289
0.937,-0.193
0.876,-0.093
0.796,0.108
0.756,0.308
0.735,0.600
0.755,0.918
0.794,1.168
0.942,1.779
1.352,3.108
1.972,5.129
2.061,5.403
2.317,6.160
PEDIT
L W 0.02 F
Example 4.4. In order to draw a body plan in an efficient manner a small FORTRAN program can be
prepared. This program’s main input is an offset file in the following format
OFFSET FILE
142.000000 19.086000 6.160000 13.838712
23
5
0.000000 0.000000 5.550000 station 0
0.000000 2.100000 5.650000
0.000000 3.800000 5.750000
0.000000 4.700000 6.000000
0.000000 5.066500 6.160000
12
7.101625 0.000000 4.638187 station 1
7.101625 0.425926 4.688814
7.101625 1.880353 4.902474
7.101625 2.977689 5.080120
7.101625 3.881452 5.240041
7.101625 4.643124 5.395631
7.101625 4.984827 5.487795
7.101625 5.307661 5.600055
7.101625 5.615051 5.739171
7.101625 5.902462 5.907385
7.101625 6.163370 6.105809
7.101625 6.223200 6.160000
4.4
COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4
BODY PLAN
**********************************************************************
* EXAMPLE_4_4.FOR *
**********************************************************************
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
REAL L
DIMENSION NW(99),X(99,99),Y(99,99),Z(99,99),Y1(99),Z1(99)
OPEN(UNIT=1,FILE='DTMB5415.DAT')
OPEN(UNIT=7,FILE=' Example4_4.SCR')
**********************************************************************
* READ OFFSETS FROM DATA FILE *
**********************************************************************
* L : LENGTH *
* B : BREADTH *
* T : DRAUGHT *
* D : DEPTH *
* NS : NUMBER OF STATIONS *
* NW : NUMBER OF WATERLINES *
* X(NS,NW) : LONGITUDINAL POSITION OF STATIONS *
* Y(NS,NW) : HALF BEAM FOR EACH OFFSET POINT *
* Z(NS,NW) : HEIGHT FOR EACH OFFSET POINT FROM BASELINE *
**********************************************************************
READ(1,*)L,B,T,D
READ(1,*)NS
DO I=1,NS
READ(1,*)NW(I)
DO J=1,NW(I)
READ(1,*) X(I,J),Y(I,J),Z(I,J)
ENDDO
ENDDO
NMID = 11
* AUTOCAD PLOTTING ROUTINE
GEN = 2.0*B
YUK = 2.0*D
WRITE(7,102)'LIMITS 0,0'
WRITE(7,103) GEN,YUK
WRITE(7,104)'ZOOM'
WRITE(7,105)'A'
* PLOT WATERLINES
WRITE(7,107)'COLOR'
WRITE(7,101)'YELLOW'
WRITE(7,107)'PLINE'
DO J=1,NW(NMID)
YW1 = B-B/2.-B/15.
YW2 = B+B/2.+B/15.
ZW1 = Z(NMID,J) + T/2.
WRITE(7,103) YW1,ZW1
WRITE(7,103) YW2,ZW1
WRITE(7,101)'PLINE'
ENDDO
YW1 = B
ZW1 = T/2.
ZW2 = T/2.+D
WRITE(7,103) YW1,ZW1
WRITE(7,103) YW1,ZW2
* PLOT SECTIONS
WRITE(7,101)'COLOR'
WRITE(7,107)'WHITE'
WRITE(7,107)'PLINE'
DO I=1,NS
DO J=1,NW(I)
Y1(J) = B+Y(I,J)
Z1(J) = Z(I,J)+T/2.
IF(I.LE.NMID) Y1(J)=B-Y(I,J)
ENDDO
DO J=1,NW(I)
WRITE(7,103)Y1(J),Z1(J)
ENDDO
4.5
COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4
WRITE(7,101)'PEDIT'
WRITE(7,105)'L'
WRITE(7,105)'F'
WRITE(7,105)'W'
WRITE(7,106)0.025
WRITE(7,101)'PLINE'
ENDDO
WRITE(7,101)'REDRAW'
100 FORMAT(I1)
101 FORMAT(A6)
102 FORMAT(A10)
103 FORMAT(E10.5,',',E10.5)
104 FORMAT(A4)
105 FORMAT(A1)
106 FORMAT(E10.5)
107 FORMAT(A5)
STOP
END
This program generates the following script file and the AUTOCAD drawing
LIMITS 0,0
.38172E+02,.27677E+02
ZOOM
A
COLOR
YELLOW
PLINE
.82706E+01,.30800E+01
.29901E+02,.30800E+01
PLINE
.19255E+02,.82257E+01
.19339E+02,.91543E+01
.19350E+02,.92400E+01
……….
PEDIT
L
F
W
.25000E-01
PLINE
REDRAW
4.6
COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4
4.7
COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4
4.8
COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4
LBP 142.0000 m
BEAM 18.9000 m
AUTOCAD SCRIPT 16
DRAUGHT 6.1600 m
DEPTH 13.8387 m
NO OF STATIONS 23 14
STATION 1
NO OF OFFSETS 20
X Y Z 12
4.9
COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4
Homework Assignment No 4
Prepare a script file for body plan of a container vessel with following nondimensional offsets.
Y
STA 0h 0.25h 0.5h 0.75h 1.0h 1.5h 2h 3h 4h 5h 6h 7h 8h 9h 10h 11h 12h 13h 14h
(T)
-0.5 0 0 0 0 0 0 0 0 0 0 0 0 177 332 441 539 617 683 732
-0.25 0 0 0 0 0 0 0 0 0 0 0 0 254 395 506 598 676 734 777
0 0 0 0 0 0 0 0 0 0 0 0 108 325 456 568 663 738 795 839
0.5 0 0 0 0 0 0 0 0 0 0 0 277 440 572 682 774 845 898 934
1 17 28 39 48 54 63 71 80 86 109 229 413 558 673 773 850 917 963 986
1.5 72 117 135 149 159 176 187 202 217 273 397 529 660 768 850 915 964 992 1000
2 145 218 250 272 285 309 319 342 366 432 528 639 749 837 904 954 985 1000 1000
3 295 399 451 485 509 544 568 604 639 685 748 815 875 923 959 983 997 1000 1000
4 447 580 631 668 694 734 766 811 844 871 898 925 950 971 985 997 998 1000 1000
5 573 715 771 805 829 866 893 926 945 958 969 978 984 991 996 999 1000 1000 1000
6 671 797 853 885 911 941 957 975 985 991 996 998 1000 1000 1000 1000 1000 1000 1000
7 736 843 889 920 946 974 988 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
8 757 871 912 941 962 988 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
9 757 871 912 941 962 988 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
10 757 871 912 941 962 988 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
11 757 871 912 941 962 988 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
12 757 871 912 941 962 988 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
13 757 871 912 941 962 988 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
14 708 827 875 905 930 961 981 997 998 999 1000 1000 1000 1000 1000 1000 1000 1000 1000
15 636 741 793 830 857 897 928 961 975 982 987 991 995 997 999 1000 1000 1000 1000
16 493 610 664 701 730 777 813 863 893 911 922 928 935 943 954 963 973 981 988
17 336 447 502 538 567 610 643 693 728 754 776 794 810 830 852 877 901 928 951
18 172 293 338 369 391 424 448 478 497 515 532 550 573 605 647 701 763 826 884
18.5 98 218 263 289 311 341 360 377 383 388 394 406 425 460 516 591 674 756 833
19 39 149 193 221 241 268 284 292 287 276 264 262 271 302 364 455 562 665 758
19.5 7 98 138 166 188 215 230 238 222 194 165 145 138 159 216 315 434 549 658
20 0 56 99 127 146 174 190 201 183 141 86 38 7 26 70 150 263 391 522
20.25 0 0 0 71 105 142 162 173 151 95 0 0 0 0 0 0 148 269 436
20.5 0 0 0 0 0 0 23 76 0 0 0 0 0 0 0 0 0 150 329
4.10
COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4
4.11