Вы находитесь на странице: 1из 60

-

AUTOCAD

-
2006

. .
, . .
AutoLisp
VisualLisp.
.
.

- - .

. .
. .

27.04.06. 6084 1/16. . .


. . . 3,54. . -. . 3,9. 150 . 228

190000, -, . . , 67

-

, 2006


AutoCad . AutoCad ,

. AutoCad , .
AutoCad AutoLisp (
Common LISP), 1986 . Autodesk; LISP
LISting Processing ( ). AutoLisp ,
.

AutoLisp
.

1. AUTOLISP
1.1.
AutoLisp:; ; ; ; ; ;
AutoCad; AutoCad; (subr).
AutoLisp .
, ,
() ; . ; ;
; ; . ,
. , .
. . LISP.
, .
:
:
( 34 26.8)
12.6
(CAT EATS MOUSE)
MOUSE
(1 (12 9.28) ( ))
()
(setq point (100.0 25.2 7.8))
(* 2 5)
, .
(
).
-2147483648 2147483647.
GETINT -32768 +32767.
4


.
2.12
3.11592652543
-92722.121344
1.23544+17.
AutoLisp .
AutoLisp TYPE :

INT
REAL
STR
FILE
LIST
SUBR
SYM






AutoLisp

(, ), .
,
.
( 1 2 N)
:
T , ,
Nil (
),
Pi 3.14159,
Pause , AutoCad.
; .
1.2. AutoCad
AutoCad , ,
, .
5


. :
;
( , ).

(getvar ),
(setvar ).
1.3.
(setq <1> <1> [<2> <2> <N> <N>])
: (setq a bb b 2.5 c (0 0))
AutoCad. !,
, , AutoLisp.
Command: !b <ENTER>
Command:!a
bb
(set a 3) (setq a 3)
(set b c) c
(set a (+ k f)) (+ k f)
2. AUTOLISP
(defun VVOD()
.
.
.

; VVOD
; ()
;

)
(defun GEOM()
.
6

;
; GEOM()

.
.
)
(defun C:Myfunc()
(VVOD)
(GEOM)
)

;) Myfunc.
; VVOD
; GEOM

, My.lsp. ,
VisualLisp.
1. My.lsp :
AutoCad
(load My [ ])

(load E:\\Student\\My)
,
. , AutoCad , .
Files Support File Search Path c
Add .
load
. , .
My.lsp
:
(vl-load-all <>)
T .
2. . 1
Myfunc
:
(command (C:My))
(vl-cmdf (C:My))

3. VISUALLISP
3.1.
,
,
.

Check Edit Window. Build Output

( ).
[CHECKING TEXT myprog.lsp loading...]
; Check done.
,
error malformed list on input ( ) ;
extra right paren on input ( );
malformed string on input ( ) ;
too few arguments in SETQ ( SETQ) setq.

Check Selection.
3.2.

,
, , , . , . , .
.
:
;

, CTRL+],
8

CTRL. .
CTRL + [ .
3.3.

Format Edit Window.

Format Selection.
(. 1):
Tools ()\Environment Options( )\Visual
Lisp Format ( Visual LISP).

3.4.
.

Load active edit window. -

. .

.
:
(defun mo ()
(setq p0 nil p1 nil p2 nil p3 nil)
(setq a 100 b 100 )
(setq p0 (list 0 0))
(setq p1 (polar p0 0 a)
p2 (polar p1 (/ pi 2.0) b)
p3 (polar p2 pi a)
)
(command _LINE p0 p1 p2 p3 _C)
)
9

. 1. :
;

10

,
, . . (mo). .
3.5.
, , . . .
. .

Debug () \ Animate (), a , (mo). .
. , .
, BREAK.
VLISP: Tools () \ Environment Options ( ) \ General Options ( )\ Diagnostic ().


: ,
, ,
. , .
, . .
-

11

Watch, . , , .

,
, .
.

Toggle breakpoint

VLISP.
. ,
. , ,

continue.

.
AutoCad,
( , ). ( ),
Visual LISP

,
.

. ,

12

4.
4.1
AutoCad : ()
(). , .

(s e tq <> '(X Y))


(s e tq <> (lis t X Y))
c (X Y)

(s e tq p0 '(100.5 50.25))
(s e tq p0 (lis t 100.5 50.25))

(polar <> < > <>)


,

;
X

(s e tq p1 (polar '(10 20) 0 200))


(s e tq p2 (polar p0 (/ pi 4.0) 100))


(dis tance < 1> < 2>)

,
(angle < 1> < 2>)
, 1 2
.

(inte rs < 1> < 2>
(a 1 2) ( < > < 4> [par])
4). .
par
nil, , , .

. par ,

.
( ),
nil

13


AutoCad. (osnap
<> <>), , ,
. , , , , ,
_end ();
_nod () ,
_mid ();
_qua ()
_int ()
_cen ( )
_nea ()
, (setq pt2 (osnap pt1 _end, _mid))
4.2.
AutoLisp
, . ,
, .
, , .
, (,
2.0 , ). :

(+ <1> <2> ...)


(setq a (+ 1 3))  4
(- <1> <2> ...)
(setq a ( - 10 4 7))  - 1
1,
0
(* <1> <2> ...)
(/ <1> <2> ...) 1 2
,

(/ 3 2 )  1 (/ 5 7)  0
(/ 5 7.0)  0.714286
(1+ <>)
1
(1- < >)

14

(abs <>)

(s in <>)
(cos <>)
(atan <1>
[<2>])

( < >)

(e xpt < >


< >)


(abs - 1.1)  1.1
,

,

< 2>, < 1> , [pi, - pi] .
, < 1>/< 2> -
. < 2> ,
< 1> + 1.570796 (+90 90 )

<>
(exp 1)  2.718 (exp 0)  1.0


(expt 2 2)  4 (expt - 2 2)  4
(expt 4 1)  0 ( )
(expt 4 1.0)  0.25 (
)

4.3.

(lis t 1 2 )
(setq p0 (list 100 200 300))
100, 200, 300 ( )

(car )
(setq Xp (car p0)) Xp X p0
, . (cdr )

(setq U (cdr p0))
U (200 300)

15

.
(car (cdr p0)) (setq Yp (cadr p0))
Yp Y p0
(caddr )
.
(car (cdr (cdr p0))),
(setq Zp (caddr p0)). Zp
Z p0
(nth ) .
0
(setq d '(11 12 13 14)) (nth 0 d)  11 (nth 4 d)  nil
(las t )
nil,
(last ( ))  nil (last (16 23 90))  90
(re ve rs e )
,

(reverse (11 12 13 14))  (14 13 12 11)
(reverse nil)  nil (reverse ( ))  nil
(le ngth )
,
(length ( ))  0 (length nil)  0
(length (15 23 7 9))  4
.
(appe nd 1

2
(append (17 20 6 (10 8 1))  (17 20 6 10 8 1)
N)
(cons <1> <2>)

(cons 50 (10 20))
 (50 10 20)
(cons (10 20) (20 45)  ((10 20) 20 45)
(cons 8 0)  (8 . 0)
(cons 2 4)
 (2 . 4)
(cons 262 nil)  (262)
(me mbe r < > .
<> , <>)
nil,

(member 1(4 20 1 3))  (1 3)


(member 4 (4 2 3 6))  (4 2 3 6)
(member 0 (2 4 5))  nil (member (80 nil))  nil

(s ubs t < >
<> <>) (subst 6 5 (11 5 7 0))  (11 6 7 0)

(vl-re move
(vl- remove 4 (0 3 6 4 4 8))  (0 3 6 8)
< >
(vl- remove 5 (0 3 7 8))
 (0 3 7 8)
<>)
(cadr )

16

(apply < >


<>)
(apply * (list 2 3 5))  30. (* 2 3 5)
(apply max (list 2 3 5))  5 . .
.
(e val <>)

(setq a (list max 2 4 6 3)) (eval a)  6

(fore ach <>
<> < 1> , < 2>< N>) (<>)
(setq a (list 1 2 3 4 5)) (setq s1 0 s2 1)
(foreach p a (setq s1 (+ s1 p)) (setq s2 (* s2 p)))  120
: s1 = 15 s2 = 120
(mapcar
,
< >
. . ,
<1>

<2>
(mapcar * (2 3) (1 5))  (2 15)
<N>)
: (* 2 1) (* 3 5)

4.4.

(fix <>)

(float <>)
(rtos <>
[< >]
[<>])

(itoa < >)



(fix 10.05)  10 (fix 0.0)  0 (fix 40.45)  40

(float 15)  15.0

<>
<> 1 2 <>
.
, ,
LUNITS
LUPREC
(rtos 10.9453 1 3)  1.095E+01
(rtos 10.9453 2 3)  10.945 (rtos 10.9453 2 0)  11


(itoa 16)  16

17


. : (atoi 2.5)  2
(atof <>)
c

(atof 14)  14.0 (atof 29.03)  29.03
(angtof <> , [< >]) ,
<> AUNITS:
0 , 1 , , ,
2 , 3 , 4
(angtof 30 0)
 0.523699
(angtof 33d27'54\ 1)  0.584074

(angtos <>
[< >] ,
, [<>])

AUNITS - AUPREC
(angtos 1 0 0)  57 (angtos 1 1 3)  57d17'45\
(angtos 1 1 0)  57d
(dis tof <> ,
,
[< >])
. rtos.
(distof 1 2)  1.0
(atoi <>)

4.5.
(s trat <1>

<2> <N>) (strcat (itoa 12) - )  12-
(s trle n <1>
- <2> <N>) (strlen )  4

(s ubs tr <>
<> [< >]) (substr ABCDEF 3 2)  CD
-
(chr <>)

(chr 192)  A ()

(ASCII <>

(ascii A)  192

18

4.6. AutoLisp
,
. (. . , ) (),
(nil). (AND), (OR)
(NOT):

(and 1 2 ...)

(not )
(or 1 2 ...)

(= <1> <2> <N>)

(/= <1> <2> <N>)


(< <1> <2> <N>)

(<= <1> <2> <N>)

(> <1> <2> <N>)


. nil,
( )
nil,
(and T nil)  nil (and T T 2)  T

. nil, nil;
nil,

(
) (= - 10.0 - 10 - 10.000) T
:
(setq x (sin 0))  0.0
(setq y (sin (* 2.0 pi))  - 2.44921e- 016
(= x y)  nil

( )
, ( )
(< 2 3 30) 
(< 2 2 30)  nil
(< a b k)  T

, ( )
(<= 2 2 30)  T

, ( )
(> 30 5 3)  T

19

(>= <1> <2> <N>) , ( )


(> =30 5 5)  T
(eq <1> <a2>)
.
. T
nil
(eq 10 10.00)  T =
(eq abc ABC)  nil =
(setq a (list 1 1 1))
(setq b a) (eq b a)  T
(setq a (list 1 1 1)) (setq b (list 1 1 1))
(eq a b)  nil
(equal <1> <a2>[<>]) (

)
(equal 10.0 10)  T
(equal 3.0 3.002 0.002)  T
(equal (1.00 2.13 2.99) (1 2.13 3.0) 0.1)  T

= eq equal
=
eq ,

equal (
(minusp <>)
(zerop <>)
(null <>)
(numberp <>)
(lisp <>)

20


(minusp 0)  nil (minusp (- 51 24 39))  T
0
(zerop 0.0)  0 (zerop 1)  nil

(null tt)  nil (null ( ))  T
,

,

4.7.

(if <> <1> [<2>]) ifthen- else. . :


<1>, <>
<2>, <> nil
<2> , nil
(if (> a b) (+ a 10) (b 10))
(progn


(if (> a b)
)
(progn
(setq c 1)
(setq d (c )
setq (e d)
);end progn
(progn
(setq c 2)
(setq d (* a b))
(setq e (* d b))
); end progn
); end if
(cond (< 1> <1>.) cas e
[(< 2> <2>.)]
(defun mm()
(setq cc 1)
(cond
((= cc 1) (SETQ ABC )
(COMMAND _line (0 0 0) '(100 100 0)
(250 100 0) _C)
); end (=cc 1)
((= cc 2) (SETQ ABC )
(COMMAND _circle (0 0 0) 100)
); end (=cc 2)
(T ); >2 <1
);end cond
); end defun

21

4.8.

. .
nil
(setq i 1 factorial 1)
(while (< i n)
(setq i (+ i 1)
(setq factorial (* factorial i))
); end while
(re pe at < > < 1>
[< 2>.< N>])
<>
(setq i 1 factorial 1)
(repeat (1 n)
(setq i (+ i 1) (setq factorial (* factorial i))
); end repeat

(while <> <1>


[<2>.<N>])

5. AUTOCAD
AutoCad AutoLisp
command:
(command _ a1 2 )
.
, , .
.
, \\
pause.
_.,
_.
,
, .
:
1. LINE
(command _.LINE \\ \\ ) n
(command _.LINE pt1 pt2 )
(command _.LINE (10 30) (40 50) )
22

2. CIRCLE
(command _.CIRCLE pt1 R)
(command _.CIRCLE (0 0) 100)
(command _.CIRCLE pt1 _D D)
(command _.CIRCLE _2P pt1 pt2)
(command _.CIRCLE _3P pt1 pt2 pt3)
(command _.CIRCLE _TTR \\ \\ R) , ,
3. ARC
(command _.ARC pt1 pt2 pt3)
(command _.ARC pt1 _C pt2 _A 120) , ,
(command _.ARC pt1 _C pt2 _L 100) , ,
(command _.ARC pt1 _E pt2 _A 120) , ,
4. ERASE C
(command _.ERASE e ) e ,

(command _.ERASE e1 e2 e3 )
5. OFFSET
(command _.OFFSET a e pt1)
e
(command _.OFFSET 50 e (30 200))
6. MOVE
(command _.MOVE e pt1 pt2) e
7. COPY
(command _.COPY e pt1 pt2)
8. ROTATE
(command _.ROTATE e pt1 A) A , e ; pt1
(command _.ROTATE e pt1 _R pt2 pt3 A) pt2 pt3
, A .
9. SCALE
(command _.SCALE e pt1 m) pt1 , m .
(command _.SCALE e pt1 _R pt2 pt3 L)- pt2 pt3 , L .
10. MIRROR
(command _MIRROR ee pt1 pt2 _N) ee
, pt1 pt2
23

11. ARRAY
(command _.ARRAY e _P p1 n 360 _Y) ,
n
(command _.ARRAY e _R n_row n_col 30 50)
12. DIVIDE
(command _.DIVIDE e n)
13. MEASURE
(command _.MEASURE e L)
14. EXPLODE
(command _.EXPLODE e)
15. TEXT
(command _.TEXT pt0 0 )
(command _.TEXT _C pt0 0 )

(command _.STYLE name_st name_shrift 5 0.9 15 )


16. REGION
(command _.REGION e1 en )
17. UCS
(command _.UCS _O pt1)
(command _.UCS _3P pt1 pt2 ) 3
(command _.UCS _S a1) a1
(command _.UCS _W)
(command _.UCS _R a1)
18. POLYGON (-)
(command _.POLYGON n _E pt1 pt2)
pt1 pt2
(command _.POLYGON n ptc _I R)
(command _.POLYGON n ptc _C R)
19. DONUT
(command _.DONUT dv dn ptc1 ptc2 )
20. LAYER
(command _.LAYER _N OSI _L CENTER OSI _C 1
_OSI _S _OSI )
N ; L ;
; S , ;
M , , ;
24

LO ; U ;
ON ; OFF ;
F ; T
COMMAND,
,
.
:
(defun :My()
(setvar CMDECHO 0) ; - (
;
(setq old_osmode (getvar OSMODE));
;
(setvar OSMODE 0);
(setq a nil b nil ) ;

(setvar ORTHOMODE 1); OO;

(setvar ORTHOMODE 0); OO;

(setvar OSMODE old_osmode);


;
(setvar CMDECHO 1); -
(setq C:COIL nil); ,
;
)
6. AUTOCAD
, utoCad, ,
.
, AutoCad. . AutoLisp
,
.
25


(setq e (entlast))
(e ntge t e )
,
e
, ,
(, , . .)
,
((- 1 . < :2020500>
(0 . LINE)
(8 . 0)
(10. 73.478 160.222 0.0)
(11. 250.654 224.473 0.0))
(assoc _)
(assoc 0 ed) (0 .LINE)
(cdr (assoc 0 ed)) (LINE)
(setq P1 (cdr (assoc 10 ed)))
(setq X (car (cdr (assoc 10 ed)))) X

(e nts e l [])
, , ,
. []

(setq e (entsel \n ))
:
(<Entity name:600014> (3.00 5.00 0.00))
e (setq ed (entget (car e)))
(entnext [<

,
>])
(setq e1 (entnext))
,
nil,

(setq e2 (entnext e1))
(entlast)

26

(e ntde l <
>)


e nts e l:
(setq e3 (entnext (car (entsel ))))
, , ,

.
(setq e1 (entnext))

(entdel e1) e1
(entdel e1) e1

, .
.

(ssget)

(ssget _L)
(ssget _W (0 0) (200 100))
(ssget '(10 20))

(s s le ngth )
(ssname )


.

(selection object).
, :
<Selection set: 2>

, ,
(0 0) (200 100)
, (10 20).
(setq ss (ssget))

(setq ss (ssget))
(setq n (sslength ss))

.
0.
(setq e (ssname ss 0))

(setq sset (ssget)) sset

27

(s s me mb _
)

(ssadd)

(ssadd _)
(ssadd _
)

(s s de l _
)

28

(setq ent1 (ssname sset 0)) sset


(setq ent4 (ssname sset 3))
, . , , nil .
(setq nabor (ssget _L))
<Selection set:7>
(ssmemb (entlast) nabor) ,

(setq ss (ssadd))
,
(setq ss1 (ssadd e1))

(setq e1 (entnext)) e1

(setq ss (ssadd))
(0 )
(ssadd e1 ss) ,
e1
(setq e2 (entnext e1)) ,
e1
(ssadd e2 ss) ss,
, e2
. , , nil,

(ssdel e1 ss)

7. AUTOLISP
7.1. GET

. GET. GET
, . . , (
ENTER). ,
. .
GET. . \n ,
.

(getint [ ])
(ge tre al [ ])
(getstring [ ] )
(ge tpoint [] [
])

(getdist [] [
])

(ge tkword [])


(setq m (getint \n ))

(setq rast (getreal \n ))

(setq st (getstring \n ))
X Y,
[], ,
[], .
(setq pt1 (getpoint \ ))
,
[].
. [] ,

(setq s (getdist \n ))
,

INITGET.
, AutoCad
.

29

(initget [] [])

, GETKWORD

(initget 1 )
(setq reply (getkword ?[/]:))
. initget
getint, getreal, getdist, getangle, getpoint.
[] :
1 (
<ENTER>)
2 0
4
[]

(initget 1)
(initget 3) (1) 0 (2)
(initget 7) (1), 0
(2) (4)
(initget 6) ,
0 (2) (4)
(initget 1 )

7.2.
AUTOLISP
:
DCL ( .dcl) ;
utoLisp ( .lsp).
DCL , .
. DCL .
.
, .
: , , ,
. . Autocad
base.dcl acad.dcl. base.dcl 30

, . . ! acad.dcl .
DCL- , base.dcl. .
DCL- VisualLisp
Interface Tools ( )
TOOLS (). ,
dialog label .

:e dit_box

Label=
Edit_width=

Edit _limit =

Value=
:column

:boxed_column

Label=

. ,
. Ec , ""

( ),

,
. 0,
,
,
. 132, 256
, (
). ,
. DCL- .
(
),
,
()

( ).
labe l ,

31

:row
:boxed_row

Label=

:image

Color=

Aspect_ratio=

Width=
Height=
:Radio_button

32

. ,
DCL-
, ()

( ). labe l
,
,
.

, , Autocad, ( 7):
Dialog_line ;
Dialog_foreground
( );
Dialog_background ;
Graphic_background ;
Black 0 () (
);
Red 1 (); Yellow 2 ();
Green 3 ( ); Cyan 4 ();
Blue 5 (); Magenta 6 ();
White 7 ()

(0.0),


. ,
. ,
.
. ,

Label=
Value=

,
.
, , , ; .
-
Value, ,

:Boxed_
,
radio_column
().

:Boxed_radio_row ,
, . Spacer

. , , ,
Errtile
.
, ,
error

,
.

Key=

Fixed_ eight=

Fix ed_widt h=

, . ASCII
.
, . , ,
.
. True
False ( False)
.
.
True False ( False)

33

Ok_only
Ok_cancel

Ok_cancel_help

(OK). key
accept
(OK and Cancel) , . key
(Cancel) cancel
ok_cancel (Help). key
help

7.3.
COIL.dcl.
COIL : dialog {
label = ;
:row {
: edit_box {
label= h,
mm ;
key = edit1;
fixed_width=true;
edit_limit = 6;
}
: edit_box {
label= L,
key = edit2;
fixed_width=true;
edit_limit = 6;
}
}

mm;

:row {
: edit_box {
label= R, mm ;
fixed_width=true;
key = edit3;
34

edit_limit = 6;
}
: edit_box {
label= b,
fixed_width=true;
key = edit4;
edit_limit = 6;
}
}

mm ;

: row {
: boxed_column {
label = ;
: button {
label = >;
key = pick_pt;
}
: row {
: edit_box {
label = X:;
key = x_pt;
edit_width = 7;
}
: edit_box {
label = Y:;
key = y_pt;
edit_width = 7;
}
}
}
}
:row {
spacer;
:image {
key=cir_image;
height=8;
width=14;
35

color=0;
}
spacer;
}
spacer;
ok_cancel;
errtile;
}
. 2. .
MSLIDE (),
.sld. .

. 2. COIL.lsp

:
: boxed_radio_column{
label=Direction;
fixed_height=true;
fixed_width=true;
36

:radio_button {
label=LEFT;
key=L;
fixed_height=true;
fixed_width=true;
}
:radio_button {
label=Right;
key=R;
fixed_height=true;
fixed_width=true;
}
}
7.4.
AutoLisp
DCL .
, .
AutoLisp .

(load_dialog
)

(unload_dialog
dcl_id)
(ne w_dialog
dcl_id)

DCL- . (dcl_id), new_dialog unload_dialog.


!
DCL- . nil
,
. . dcl_id DCL- (
load_dialog).
(new_dialog) T (true), nil.

ne w_dialog

37

. ne w_dialog. ,

done _dialog. done _dialog
, acce pt ( Ok) cance l ( )
(done_dialog
. .
[c])
c,

(action_tile ,
.

,
)

. ( v alue), , , $value ,
$key.

.
(set_tile
,
)
.
(ge t_tile )
.


. .
(dimx_tile )
(dimy_tile )
(s tart_image

,
)
(slide_image x1 y1 (.sld) . (0 0)
x2 y2 ) . (*.sld)
(*.slb). , .
X1 Y1 , X2 Y2
(end_image)

(start_dialog)

38

7.5. AutoLisp
(prompt \n.. );
;
(defun rs_error ()
(set_tile error ) ; ;
)
; X.
(defun do_x_pt()
(check_real (setq x_pt (get_tile x_pt)) x_pt) ;
)
; Y.
(defun do_y_pt()
(check_real (setq y_pt (get_tile y_pt)) y_pt) ;
)
; . real_number,
; nil
(defun check_real (real_number coord);
(if (distof real_number 2); distof c 2 ;
(progn
;
(rs_error) ;
;
real_number
)
(progn
;
(set_tile error ; ;
(strcat Incorrect coordinate
(strcase (substr coord 1 1))
.
)
)
nil
);end progn
);end if
);end defun check_real
39

;
; ,
; .
(defun defaults()
(if x_pt
(set_tile x_pt x_pt)
(progn
(set_tile x_pt (rtos 0.0000 2))
(setq x_pt (rtos 0.0000 2))
);end progn
);end if
(if y_pt
(set_tile y_pt y_pt)
(progn
(set_tile y_pt (rtos 0.0000 2))
(setq y_pt (rtos 0.0000 2))
)
)
(if h
;
(set_tile edit1 h)
(progn
;
(set_tile edit1 40)
(setq h 40)
)
)
(if L
;
(set_tile edit2 L)
(progn
;
(set_tile edit2 30)
(setq L 30)
)
)
(if r
;
(set_tile edit3 r)
(progn
;
(set_tile edit3 3)
40

(setq r 5)
)
)
(if b
; S
(set_tile edit4 b)
(progn
;
(set_tile edit4 3)
(setq b 3)
)
)
);end defun
; ;
(defun check_dat ()
(setq h (get_tile edit1)) ;
(setq L (get_tile edit2))
(setq r (get_tile edit3))
(setq b (get_tile edit4))
(if (or (<= (atof h) (* 2.0 (atof r)))
(<= (atof h) 0) (< (atof r) 0) (<= (atof b) 0) (<= (atof L) 0)
(>= (* (atof r) 2.0) (atof L))
)
(progn
(if (<= (atof h) 0)
(progn
(set_tile error : h > 0 !!! )
nil
)
(if (<= (atof L) 0)
(progn
(set_tile error : L > 0 !!! )
nil
)
(if (< (atof r) 0)
41

(progn
(set_tile error : r >= 0 !!! )
nil
)
(if (<= (atof b) 0)
(progn
(set_tile error : b > 0 !!! )
nil
)
(if (>= (* (atof r) 2.0) (atof L))
(progn
(set_tile error : L > 2*r !!! )
nil
)
(if (<= (atof h) (* 2.0 (atof r)))
(progn
(set_tile error : h > 2*r !!! )
nil
)
);end if
);end if
);end if
);end if
);end if
);end if
);end progn
(progn ;
(rs_error) ;
(done_dialog 1) ;
(setq what_next 1)
)
); end if
);end defun check_dat
(defun C:COIL ();
; - (
;
42

(setvar CMDECHO 0);


;
(setq old_osmode (getvar OSMODE))
(setvar OSMODE 0);
; ,
(setq h nil L nil R nil x_pt nil y_pt nil b nil)
(if (< (setq dcl_id (load_dialog COIL)) 0) (exit)); DCL; , dcl_id ; 0,
; . .
(setq what_next 6)
(while (< 2 what_next)
(if (not (new_dialog COIL dcl_id)) (exit));
;
(defaults); ;
(setq x (dimx_tile cir_image) ; ;
y (dimy_tile cir_image))
(start_image cir_image); ;
(slide_image 0 0 x y COIL); COIL.sld
;
(end_image);
(action_tile accept (check_dat));
; ;
(action_tile cancel (done_dialog 0));
; Cancel ( )
(action_tile edit1 (setq h $value));
(action_tile edit2 (setq L $value))
(action_tile edit3 (setq R $value))
(action_tile edit4 (setq b $value))
(action_tile pick_pt (done_dialog 4));
;
(action_tile x_pt (do_x_pt)); X Y ;
(action_tile y_pt (do_y_pt))
43

(setq what_next (start_dialog));


; .
(if (= what_next 4)
(progn
(setq pt1 (getpoint )); ;
(setq x_pt (rtos (car pt1) 2 4))
(setq y_pt (rtos (cadr pt1) 2 4))
)
);end if
); end while
(unload_dialog dcl_id); DCL-.
(if (/= what_next 0)
(progn
(setq h (atof h)) (setq L (atof L)) (setq r (atof r)) (setq b
; (atof b))
(setq x_pt (atof x_pt)) (setq y_pt (atof y_pt))
(setq pt1 (list x_pt y_pt)) ;
;
(setq p2 (polar pt1 0 (/L 2.0)));
(setq p21 (polar p2 (/ PI 2.0) b))
(setq pt11 (polar pt1 0 r))
(setq pt12 (polar pt1 (/ pi 2.0) r))
(setq p3 (polar (polar pt1 0 b) (/ pi 2) b))
(setq p31 (polar p3 0 r))
(setq p32 (polar p3 (/ pi 2.0) r))
(setq p4 (polar pt1 (/ PI 2.0) (/ (+ h b b) 2.0)))
(setq p41 (polar p4 0 b))
(setq pc (polar (polar pt1 0 r) (/ PI 2.0) r))
(setq pc1 (polar (polar p3 0 r) (/ PI 2.0) r))
(_$mark $COIL); $COIL (. ; acad.lsp)
(_$mark $COIL1); $COIL1 (.
; acad.lsp)
(if (= r 0)
(progn
44

(command LINE p2 pt1 p4 )


(command LINE p21 p3 p41 )

_N)

)
(progn
(command LINE pt11 p2 )
(command LINE pt12 p4 )
(command LINE p21 p31 )
(command LINE p32 p41 )
(command ARC _C pc pt12 pt11)
(command ARC _C pc1 p32 p31)
)
);end if
(command MIRROR (_$endmark $COIL) p4 (polar p4 0 L)

; $endmark , $COIL
(command PLINE p4 _W 0.5 0.5 p41 )
(command MIRROR (_$endmark $COIL1) p2 (polar p2 (/ pi
2.0) h) _N)
(command PLINE p2 _W 0.5 0.5 p21 )
(setq e1 (entlast))
(command MIRROR e1 p4 p41 _N)
)
) ;end if
(command ZOOM _E)
(command REDRAW)
(setq C:COIL nil)
;
(setvar OSMODE old_osmode)
(setvar CMDECHO 1)
(princ);
)

45

7.6.

. ACAD.lsp
ACADDOC.lsp. AutoCad
ACAD.lsp . ,
. ACAD.lsp
AutoCad. , ,
ACADDOC.lsp,
. ACAD.lsp Load ACAD.LSP
with Every Drawing ( ACAD.lsp ), System () Options (). , ACADDOC.lsp.
.
, ACAD.lsp
ACADDOC.lsp.
(defun _$rtd ($a) ;
(* (/ 180.0 pi) $a)
(defun _$dtr ($a) ;
(* (/ pi 180.0) $a)) (defun arcsin (x /)
; Arcsin ,
(cond
((= x 0.0) 0.0)
((= x 1.0) (/ pi 2))
((= x 1.0) (/ (- 0 pi) 2))
(t (atan (/ x (sqrt (abs (- 1 (* x x)))))))
)
)
(defun arccos (x /); Arccos ,
(cond
((= x 0.0) (/ PI 2.0))
((= x 1.0) 0.0)
46

((= x 1.0) PI)


(t (- (/ PI 2.0) (atan (/ x (sqrt (abs (- 1 (* x x))))))))
)
)
(defun _$mark ($mark) ;
; ;
(if (set (read $mark) (entlast))
nil
(progn
(command _POINT @)
(set (read $mark) (entlast));
(entdel (eval (read $mark)));
)
)
)
(defun _$endmark ($mark); ;
;
(if (eval (read $mark))
(progn
(setq $ss (ssadd))
(while (set (read $mark) (entnext (eval (read $mark))))
(ssadd (eval (read $mark)) $ss)
)
)
)
)
(defun _$rline (); ENTER
(prompt \n <<< To continue press <ENTER> >>>)
(read-line)
)

47

8. -

(getfiled <>
<> <>
<>)
,
. ( *)

1 (
)
4 ( )
16 ,
(getfiled D:/ doc 16)
(getfiled C D:/ doc 17)

(getfiled C D:/./a doc 1)


(findfile <>)
( ).
,
AutoCad .
nil,
(open <>
,
<>)
:
w
r
a
nil
(setq f (open A.TXT w))
(close <>) (close f)
(read- line

.
<>)
. , nil
(setq st (read- line f))
(setq st1 (read- line)) c

48

(read- char
<>)
(write- line
< >)

(write- char <>


< >)

(vl- file- delete <>)

.

. ,
,
(write- line f)
-
.
( ). 0. (write- char 50)
2 50
, T,
; nil .
(vl- file- delete a.txt)

(prompt <>) . nil


(alert <>)

OK. nil
:
(setq st (strcat AutoLisp\n \n
AutoCad))
(alert st)
(princ )
. .
(terpri)
.

:
(setq jj (open limit.dat r))
(if jj
(progn
(setq bz (atof (read-line jj)))
(setq hj (atof (read-line jj)))
)
49

(progn
(setq bz 0.8)
(setq hj 4.0)
)
)
9. VLX-
LSP-, DCL , FAS-, DVB- Visual Basic for
Applications (-). vlx. prv,
. VLX- Make
Application ( ) File (). :
New Application Wizard ( );
Existing Application Properties ( );
Make Application ( );
Rebuild Application ( ).
New
Application Wizard ( ), Wizard Mode ( ), . 3.

. 3. Wizard Mode

50

, : Simple () Expert ().


LISP- ( FAS-), DCL-, DVB- . .
Expert () Next () Application
Directory ( ). (. 4)
Application Name ( ), Application Location ( ) , vlx
prv (
).

. 4. Application Directory

Browse ().
Target File ( )
vlx. Next () (. 5) Application Options ( ). Separate
Namespace ( ) . , . (. 6) LISP
Files to Include (LISP- )
lsp ( ), fas (51

. 5. Application Options

. 6. LISP Files to Include

) prv ( ), . Add ()
Remove () , ,
. (), Up (), Down () Bottom
() LISP-52

. (LISP
source files ( LISP-),
Compiled LISP files ( LISP-) Visual LISP
project files ( Visual LISP)),
. Add () Remove
() , , . (), Up (), Down () Bottom () LISP-
. (LISP source
files ( LISP-), Compiled LISP files (
LISP-) Visual LISP project files ( Visual LISP)),
.

. 7. Resource Files to Include

(. 7) Resource Files to Include ( ) , .


, (
):
LISP source files ( LISP-);
Compiled LISP files ( LISP-);
Visual LISP project files ( Visual LISP);
53

DCL files (DCL-);


DVB files (DVB-);
Text files ( ).
(. 8)
Application Compilation Options ( ).
Standard ()
Optimize and Link ( ).
,
-

. 8. Application Compilation Options

. 9. Review Selections / Build Application

54

AutoCAD.
(. 9), , Review Selections / Build Application
( / ). Build Application ( ) Finish (), Visual LISP ( vlx) ( prv).
Finish (),
PRV-, . Make Application
( ) File (). Existing Application Properties ( ) , Rebuild Application (
) , - (DCL-, LSP- . .).
Visual LISP
LISP load Load File ( ) File
(). AutoCAD
Visual LISP, load, AutoLISP,
Load () Tools () Load Application
() .
10.

:
VisualLisp
.
:
1. .
2. DCL- .
3.
.
4. LSP- .

.
55

5. LSP-.
6.
AutoCad.
7. , :
;
-;
, ;
DCL-;
;
LSP- ;
, .
.
.


1. . . Visual LISP AutoCad. .:
-, 2001. 576 c.
2. . AutoLisp. AutoCad 14. .: ,
1999. 365 c.
3. . AutoCad: . .: -, 1995. 235 c.
4. . . AutoCad 2002. .: -, 2003. 1200 c.
5. C. ., . . AutoCad . .: -, 2004. 1168 .
6. ., ., .AutoCad 2002 .
. : , 2002. 944 .

56

57

.
9

10

11

12

13

14

15

16

58

.
17

18

19

20

21

22

23

24

59


......................................................................................................
1. AutoLisp ..................................................................
1. 1. .........................................................................................
1.2. AutoCad ........................................................
1.3. ............................................................................
2. AutoLisp ...................................................
3. VISUALLISP ..........................................................
3.1. .......................................................................
3.2. ....................................................
3.3. ...................................................
3.4. ....................................................
3.5. ...................
4. ....................................................................................
4.1 ......................................................................
4.2. ....................................................................
4.3. .......................................................
4.4. .....................................................................
4.5. ........................................................
4.6. AutoLisp ............................................................
4.7. ...........................................
4.8. .....................................................................................
5. AutoCad .......................................................
6. AutoCad ..............................................
7. AutoLisp ..................................................................
7.1. GET ................
7.2. ...................................................................................
7.3. ....................................................................
7.4. AutoLisp ...
7.5. AutoLisp ..............................................
7.6. ........................................
8. - ............................................................
9. VLX- ...........................................................................
10. .....................
.............................................................................
.......................................................................................................

60

3
4
4
5
6
6
8
8
8
9
10
11
13
13
14
15
17
18
19
21
22
22
25
29
29
30
34
37
39
46
48
50
55
56
57