0% found this document useful (0 votes)
7 views

CASDLectureNotes_4

Chapter 4 of the Computer Aided Ship Design lecture notes introduces AutoCAD script files, which are text files containing commands to automate tasks in AutoCAD. It explains the structure, limitations, and specific commands related to scripts, emphasizing their utility in reducing keystrokes and enhancing efficiency in drawing processes. Additionally, examples demonstrate how to create scripts for body plan drawings using offset data.

Uploaded by

eberber05
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

CASDLectureNotes_4

Chapter 4 of the Computer Aided Ship Design lecture notes introduces AutoCAD script files, which are text files containing commands to automate tasks in AutoCAD. It explains the structure, limitations, and specific commands related to scripts, emphasizing their utility in reducing keystrokes and enhancing efficiency in drawing processes. Additionally, examples demonstrate how to create scripts for body plan drawings using offset data.

Uploaded by

eberber05
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4

4. INTRODUCTION TO AUTOCAD SCRIPT

4.1. Autocad Script Files

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:

line 1,1 2,2


circle 2,2 1,1

The Drawbacks to Scripts

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.

Script Commands and Modifiers

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:

; Pause script for ten seconds:


delay 10000

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.

Backspace is the key used for pausing a script file.

Esc stops a script file dead in its tracks; use the RScript command to start it up again from the beginning

The following commands are useful in scripts:

DELAY Provides a timed pause within a script (in milliseconds)


GRAPHSCR Switches from the text window to the drawing area
RESUME Continues an interrupted script
RSCRIPT Repeats a script file
TEXTSCR Switches to the text window

Example 4.1. Set limits to -10,-10 10,10 and draw a line 0,0 0,5

LIMITS -10,-10 10,10


ZOOM A
GRID 10
LTSCALE 3.0
LAYER SET 0 COLOR RED

LINE
0,0
0,5

Example 4.2. To create a script that rotates the line

ROTATE L
0,0 -6
DELAY 1000
RSCRIPT

4.2
COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4

4.2. Script File for Body Plan Drawing

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

Then the script file (Section.scr) is

;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

Private Sub CommandButton1_Click()


'
' EXAMPLE_4_4.XLSM - PREPARES SCRIPT FILE FOR DTMB5415 SECTION
'
Dim LBP As Double, BEAM As Double, DRAFT As Double, DEPTH As Double
Dim NS As Integer, NW(1 To 99) As Integer, NWC(1 To 99) As Integer
Dim i As Integer, j As Integer, NMID As Integer
Dim X(1 To 99, 1 To 99) As Double, Y(1 To 99, 1 To 99) As Double, Z(1 To 99,
1 To 99) As Double
Dim GEN As Double, YUK As Double
Dim YW1 As Double, YW2 As Double, ZW1 As Double, ZW2 As Double
Dim Y1(1 To 99) As Double, Z1(1 To 99) As Double
'
' OPEN SCRIPT FILE
'
Open "f:\CASD\excel\4\EXAMPLE_4_4.SCR" For Output As #1
'
' READ MAIN DIMENSIONS
'
LBP = Range("B1").Value
BEAM = Range("B2").Value
DRAFT = Range("B3").Value
DEPTH = Range("B4").Value
'
' READ NUMBER OF STATIONS
'
NS = Range("B5").Value
'
' READ NUMBER OF OFFSETS
'
NW(1) = 20
NW(2) = 19
NW(3) = 21
NW(4) = 23
NW(5) = 25
NW(6) = 24
NW(7) = 26
NW(8) = 29
NW(9) = 30
NW(10) = 30
NW(11) = 30
NW(12) = 31
NW(13) = 32
NW(14) = 25
NW(15) = 27
NW(16) = 25
NW(17) = 26
NW(18) = 19
NW(19) = 36
NW(20) = 37
NW(21) = 46
NW(22) = 56
NW(23) = 53
'
NWC(1) = 7
For i = 2 To NS
NWC(i) = NW(i - 1) + NWC(i - 1) + 3
Next i
'
'
' LOOP FOR STATIONS
'
For i = 1 To NS
'
' READ OFFSETS
' X(NS,NW) : LONGITUDINAL POSITION OF STATIONS
' Y(NS,NW) : HALF BEAM FOR EACH OFFSET POINT

4.7
COMPUTER AIDED SHIP DESIGN LECTURE NOTES – CHAPTER 4

' Z(NS,NW) : HEIGHT FOR EACH OFFSET POINT FROM BASELINE


'
For j = 1 To NW(i)
X(i, j) = Cells(NWC(i) + 1 + j, 2).Value
Y(i, j) = Cells(NWC(i) + 1 + j, 3).Value
Z(i, j) = Cells(NWC(i) + 1 + j, 4).Value
Next j
Next i
'
' NO OF MIDSHIP SECTION
'
NMID = 11
'
' AUTOCAD PLOTTING ROUTINE
'
GEN = 2 * BEAM
YUK = 2 * DEPTH
Print #1, "LIMITS 0,0"
Write #1, GEN, YUK
Print #1, "ZOOM"
Print #1, "A"
'
' PLOT WATERLINES
'
Print #1, "COLOR"
Print #1, "BLUE"
Print #1, "PLINE"
For j = 1 To NW(NMID)
'For j = 1 To NW(1)
YW1 = BEAM - BEAM / 2 - BEAM / 15
YW2 = BEAM + BEAM / 2 + BEAM / 15
ZW1 = Z(NMID, j) + DRAFT / 2
'ZW1 = Z(1, j) + DRAFT / 2
Write #1, YW1, ZW1
Write #1, YW2, ZW1
Print #1, " PLINE"
Next j
YW1 = BEAM
ZW1 = DRAFT / 2
ZW2 = DRAFT / 2 + DEPTH
Write #1, YW1, ZW1
Write #1, YW1, ZW2
'
' PLOT SECTIONS
'
Print #1, " COLOR"
Print #1, "WHITE"
Print #1, "PLINE"
For i = 1 To NS
For j = 1 To NW(i)
Y1(j) = BEAM + Y(i, j)
Z1(j) = Z(i, j) + DRAFT / 2
If i <= NMID Then Y1(j) = BEAM - Y(i, j)
Next j
For j = 1 To NW(i)
Write #1, Y1(j), Z1(j)
Next j
Print #1, " PEDIT"
Print #1, "L"
Print #1, "F"
Print #1, "W"
Write #1, 0.025
Print #1, " PLINE"
Next i
Print #1, "REDRAW"
Close #1
End Sub

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

0.000002 0.000000 5.717318 0.000000


0.000002 0.213471 5.718955 -0.213471 10
0.000002 0.481299 5.737862 -0.481299
0.000002 0.927629 5.811613 -0.927629
0.000002 1.278856 5.897250 -1.278856 8
0.000002 1.579619 5.991241 -1.579619
0.000002 2.024500 6.160000 -2.024500
6
0.000002 2.205946 6.229000 -2.205946
0.000002 2.207425 6.229613 -2.207425
0.000002 2.558026 6.383152 -2.558026 4
0.000002 2.936544 6.576611 -2.936544
0.000002 3.336335 6.825294 -3.336335
0.000002 3.755891 7.140982 -3.755891 2
0.000002 3.962164 7.313723 -3.962164
0.000002 4.192735 7.517911 -4.192735
0
0.000002 4.640212 7.945737 -4.640212 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11
0.000002 5.142491 8.475628 -5.142491
0.000002 5.551518 8.953360 -5.551518 -2
0.000002 5.914978 9.402579 -5.914978
0.000002 6.794743 10.980402 -6.794743
-4
STATION 2
NO OF OFFSETS 19
X Y Z
7.101625 0.000000 4.638187 0.000000
7.101625 0.425926 4.688814 -0.425926
7.101625 1.880353 4.902474 -1.880353
7.101625 2.977689 5.080120 -2.977689
7.101625 3.881452 5.240041 -3.881452
7.101625 4.643124 5.395631 -4.643124
7.101625 4.984827 5.487795 -4.984827
7.101625 5.307661 5.600055 -5.307661
7.101625 5.615051 5.739171 -5.615051
7.101625 5.902462 5.907385 -5.902462
7.101625 6.163370 6.105809 -6.163370
7.101625 6.223200 6.160000 -6.223200
7.101625 6.391250 6.335553 -6.391250
7.101625 6.582142 6.597323 -6.582142
7.101625 6.742288 6.890167 -6.742288
7.101625 6.880511 7.212736 -6.880511
7.101625 7.005622 7.563661 -7.005622
7.101625 7.293119 8.531242 -7.293119

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

Main dimensions of the vessel are given as follows:

Student No Name Length Breadth Draught


1 080190017 Ata Emir Erdoğdu 80 16 6
2 080200003 Ayşegül Özşen 90 18 6
3 080200019 Cemal Yasin Atasoy 100 20 8
4 080200020 Alper Toprak 110 22 10
5 080200034 Yiğitcan Tilaver 120 24 10
6 080200040 Sefa Ramazan Nacakcı 130 26 12
7 080200052 İlker Aksoy 140 28 14
8 080200059 Emre Berber 150 30 14
9 080200065 M. Mustafa Karakaya 160 32 16
10 080200070 Ekin Saraçoğlu 170 34 18
11 080200071 Burak General 180 36 18
12 080210057 Yağmur Tuncay 190 38 20
13 080210069 Emre Altun 200 40 22
14 080220026 İsranur Bülbül 210 42 22
15 080220713 Ceylan Şavluk 220 44 24
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

4.11

You might also like