You are on page 1of 751

1

AutoLISPVisual LISP

1.1 LISP
LISP

LISPLISP
LISP
LISP
LISPLISP
Autodesk19852.1
LISP19862.5
AutoLISP
LISPMacLISPInterLISP
ZetaLISPCommonLISPCommonLISP
BellDECHP
MacLISPInterLISP
ZetaLISP
LISP

1.2 AutoLISP
AutoLISPAutoCADLISP
AutoCADLISPAutoCAD

AutoLISP CommonLISP
CommonLISPAutoCADLISP
AutoCAD
AutoLISPAutoCAD
AutoCAD
AutoLISP
AutoCADAutoCAD

1.3 Visual LISP


Visual LISPAutodesk199714
AutoLISP
Visual LISP

Visual LISPMicrosoft

Visual LISPAutoLISPVisual LISP


AutoLISP

VLISPAutoLISP

Visual LISPAutoLISPAutoLISP
Microsoft ActiveX Automation
AutoCADAutoLISP

Visual LISPAutoLISP
vl-load-com

acad2006doc.lsp

AutoLISP

AutoCADAutoCADVLA

2.1
1. INT

3221474836482147483647

2. REAL
-110
.50.5
14Visual LISP

3. STR

100100100
""0

\nnn\ASCII
nnnASCII
ABCD\101\102\123\104
\nnn
\\\\"

2-1

\ASCII

\\

\134

"

\"

\042

Esc

\e

\033

\n

\012

\r

\015

Tab

\t

\011

enrt

4.

+ 1 2 3sin * 0.5 pi
A BA B C C D0 "LINE"
10 1.5 2.6 0.0

+ 1 2 3
4sin * 0.5 pi2A B C
C D30
1.5 3.6
X1.5Y3.6,2.5 2.0 1.0
X2.5Y2.0Z1.0

5. SUBS

AutoLISPAutoLISP

ADSADSRXARXsin cos
sqrt
AutoLISP
*/<<=

>

AutoLISPif while

6. FILE
AutoLISP
myfile.dat
f1
(setq f1 (open "myfile.dat" "r")) <File:#34614>

7. ENAME
AutoCAD16
AutoLISP

8. PICKSET

AutoLISP

9. VLA
VLA ActiveX
VLA

VLAAutoCADVLA

2.2
2.2.1
SYMBOL

'"
a1b2 c_3(a)b.c4"5
[1]{2}~3!4/51a3c-d
+eb-2c*3

AutoLISP

6
6

2.2.2
AutoLISP

AutoLISP

setqsetq a 5,
a5,setq b 2.5
, bsetq c "ABC",c

setq a 5a
setq a "ABC" a
typetype a INT
atype bREALb

type c STRc

2.2.3
setq
(setq 1 1[2 2 . . .])
Command(setq x 1.5 y 20 p "Center")
Center

xyp
Center
Center
Command(setq v(setq x 1.5 y 20 p "Center") )
Center
xyp,
CentervCenter

2.2.4
AutoLISPnilTPausePi
AutoLISP

1 nil
nilnil0
0
x+ 1 x
error: bad argument type
nil

nil
false

2T
T
true
3PAUSE

PAUSEcommand

4PI
PI

nil


AutoLISP

sinsetq sin 1

sin1

2.2.5
AutoCAD
!xv

Command!x
1.5

Command!v
"Center"
Command!z
nilz

2.2.6 AutoCAD

AutoCAD
Command(setq p '(20 10) r 5)
Commandcircle
Specify center point for circle or [3P/2P/Ttr(tan tan radius)]!
p

Specify radius of circle or [Diameter]:!r


20105

2.3
AutoLISP

2.3.1

512.5ABC"

( [])

2.3.2

x=2.5y=1+2
AutoLISP
(setq x 2.5)(setq y(+ 1 2))
x=(a+b)*c AutoLISP
(setq x(* (+ a b) c))

AutoLISP

2.3.3
LISP

(setq x(* (+ a b) c))ab


ab cxx

CommandAutoCAD
AutoCAD6
Commandsin 0.5
0.479426

_>

("_>

Esc

2.3.4
1

2
3

+ * 2 3 / 50 3
* 2 3 / 50 36
16+ 6 16
+ 6 1622

25 a b cerror: bad function:

252525

(fx a b c) error: no function


definition: FX fx

quote

3 2 1psetq p3 2 1

, error: bad function: 3


13
quote

setq p quote3 2 13 2 1
3 2 1p3
quoteAutoLISP
'(quote (10 20))'10 20

10 202p2
setq p2 '10 20

2.4

12
AutoLISP

1.
setq radius 103

(a)
6setq fillet_radius 5

(b)

2.

3.

(A B C D)A B CD E setq x
+ * a d

4. dotted pair

.
0 . "LINE"(8 . "A1")(40 . 15.0)

AutoLISP

2.5
AutoLISP

AutoLISP
AutoLISPAutoLISP
AutoLISPADSADSRXARX

2.5.1 AutoLISP
defun
(defun (... / ... ) ...)

AutoLISP

nil

2-110
(defun add10(x)
(setq x(+ 10 x))
)

(defun add10(x)
(+ 10 x)
)
add10x
(setq x(+ 10 x))(+ 10 x)

2-2

(defun volume(r h / v)
(setq v(* r r pi h))
)
volume rh
v(setq
r r pi h))

v(*

2.5.2 AutoLISP
AutoLISP

( [])

0
sqrt 4sqrt4

+ 1 2 3+12
33

(sqrt (+ 1 2 3))


sqrt 4 , 2
+ 1 2 3 , 6
Tnil

< 1 2, T
not 1nil
,
add10 3
(setq y(add10 (+ 2 3)))
(volume 12.5 20)1)

2.5.3 AutoLISP
AutoLISP

2-3

01nnn-1

(defun factorial(x)

(if (= x 0)
1
(* x (factorial (- x 1)))
)
)

2.5.4 AutoCAD
AutoLISPcommandAutoCAD
command AutoCAD "" )
2-4(2,4)5
command "circle" "2,4" 5)
command "circle" (2 4) 5)
2-5p1p2p3

command "circle" "3p" p1 p2 p3)

2-6p100)p2100)
command "line "0,0 "10,0 "")
command "line" '(0 0) '(10 0) "")
command "line" (list 0 0) (list 10 0) "")
command "line p1 p2 "")p1p2
Specify next point
or [Undo]:line

2.5.5 AutoCAD
AutoCADdefun
(defun C:AutoCAD (/ ... ) ...)
AutoCAD

C:

AutoCAD
AutoCAD

2-7

(defun c:rect1( / p1 p2 p3 p4) p1p2p3p4


(setq p1 (getpoint "\n" ))
(setq p3 (getcorner p1 "\n" ))
(setq p2(list (car p3) (cadr p1)))

p4

p3

p1

p2

(setq p4(list (car p1)(cadr p3)))

(command "pline" p1 p2 p3 p4 "c")


)

AutoCADCommand
rect1
)

AutoLISP

3.1
AutoLISP
3.1.1
1. (cond (1 1) [(2
2)] )

i 1n=12n=4
3n=10n=100condn
i

2
2

n
n

2
2

n
n

(setq n(cond ((<= i 1) 1)

((<= i 2) 4)
((<= i 3) 10)
(t 100)
)
)
Cswitch
tTCdefault
i 5n100C
switch
i 0
(<= i 1)1
n1

2.if 1 [2]
1
2
(if (> a 1) (setq b 2) )
a 1b2

(if (> a 1) (setq b 2) (setq b 3) )


a 1b2b3

31
2

(if (> a 1)
(setq b 2)
(print ( b a))
(setq b 4)

(print b)
)
b2ab
b4b
if1
(> a 1)2
(setq b 2)3
(print ( b a))
too many arguments

(if (> a 1)
((setq b 2)
(print ( b a))
)
((setq b 4)

(print b)
)
)

3error: bad function: 2


(setq b 2)
2
progn

3. (prong ...)
nif
n,

(if (> a 1)
(progn (setq b 2)

(print ( b a))
)
(progn (setq b 4)
(print b)
)

)
b2a
babb44
4

3.1.2
1. (repeat n )
n

(setq a 1 b 100)

(repeat 10
(setq a(+ 1 a))


(setq b(+ 10 b))

)
a11b200200

2. (while )
nil, nil
(setq i 1 a 10)
(while (<= i 10)
(setq a(+ a 10))

(setq i (1+ i )
)
i11a11011

20.5100100
0

2040
176
97100201

323366
9910032
100100

3-1
(defun chicken( / hen cock chick cost)
(setq hen 1)
(while (< hen 20)20
(setq cock 1)
(while (< cock 32)32
(setq chick (- 100 hen cock))
(setq cost (+ (* 3 hen)(* 2 cock)(* 0.5 chick)))3
(if (= cost 100)
(print (list "=" hen " =" cock " =" chick))
)
(setq cock (1+ cock))1
)
(setq hen (1+ hen)) 1
)
(princ)
)


3(setq hen 1)4(while (< hen 20)
hen

5(setq cock 1)3(setq hen 1 cock 1)


cock132
32
12(setq cock (1+ cock))(1+ cock)
(1+ cock)cock+1cock1+ C
++
10(print (list = hen = cock = chick))
(print = hen = cock = chick)
print
(princ)

print

Command:
(chicken)
("=" 2 " =" 30 " =" 68)
("=" 5 " =" 25 " =" 70)

("=" 8 " =" 20 " =" 72)


("=" 11 " =" 15 " =" 74)
("=" 14 " =" 10 " =" 76)
("=" 17 " =" 5 " =" 78)

3.2 AutoLISP
3.2.1 AutoLISP
AutoLISP.lspAutoLISP

LISPAutoCAD

(defun plus(x y)
(+ (* x y) x)
)

(setq a 2.0) (setq b 4.0) (+ a b)

AutoLISP

f(x)

1x 0

f ( x ) 2 x 0
0x 0

(defun fun(x) (cond ((> x 0) 1) ((= x 0) 2) ((< x 0) 0)))


(defun fun(x)
(cond((> x 0) 1)
((= x 0) 2)
((< x 0) 0)
)
)
Visual LISP

3.3.2

(setq area (* pi r r))


||

(setq tmode || (getvar "tilemode"))

(setvar "orthomode" 1) |
,
......
| (princ "\nORTHOMODE set On.")

3-2ASCII33 ~ 90

ASCII33 ~ 90
Command:pras
(defun c:pras(/ as )
(setq as 33)

asASCII33

(while(<= as 90)

while

prasAutoCADas

(princ(chr as))

ASCIIas

(terpri)

(setq as (1+ as))

asas ASCII
while

3.2.3 AutoCADAutoLISP
1
AutoLISPloadload

Command(load

":\\\\"

["

"])

lisp

fi1e1.lspfunc1
d:\user1
Command(load
" )

"d:\\ user1\\ fi1e1"

"

func1"
"

Command(load

"d:/ user1/fi1e1")

func1; error: LOAD


failed: " d:\\ user1\\ fi1e1".

2
ToolsLoad Application ,
ToolsAutoLISPLoad,Command
apploadLoad/Unload Applications
AutoLISP

3.
AutoCAD acad.lsp
acad2006.lsp acaddoc.lsp acad2006doc.lsp

lisp
acad.lsp acaddoc.lsp

AutoCAD
AutoCAD

.mnllisp

4.
autoload
acad2006doc.lspAutoCAD
acad2006doc.lsp
autoload lisp
autoload
Command(autoload

lisp

lispAutoCAD
lisp
AutoCAD
nil

autoloadload

AutoCADlisp
lisp
lisp
lispAutoCAD
lisp
lisp

file1.lsp cmd1 cmd2


AutoCAD AutoCAD support

autoloadfile1.lsp

Command (autoload
"cmd2")

"file1.lsp"

"cmd1"

file1.lsp
Unknown command"".
lisp
cmd1
file1.lspAutoCAD
AutoCAD
(autoload " file1.lsp" "cmd1"
"cmd2")acad2006doc.lsp
AutoCADfile1.lsp

4
Visual LISP

4.1 Visual LISP


1. Visual LISP
AutoCAD ToolsAutoLISPVisual
LISP EditorCommandvlide
Visual LISP

2. Visual LISP
Visual LISPFileExit
AutoCADVisual
LISPVisual LISP
Visual LISPVisual LISP

3. AutoCAD
Windows
Visual LISPWindowActivate AutoCAD
View
AutoCAD

4.2 Visual LISP

Visual LISP9

FileAutoLISP

Edit

Search

View

Project
Debug
ToolsVisual LISP

Window
Help

Visual LISPStandardViewDebugToolsSearch

Standard

Tools

View
AutoCAD

Search

Debug

3
Visual LISP

AutoLISP
AutoLISP

4
Visual LISP
AutoCAD
AutoLISP

Visual LISP

5
,Visual LISP
Edit: d:/lisp1/roots.lsp *
*
Visual LISP console window
Trace output window

6
Visual LISP
Visual LISP

4.3
AutoCAD
AutoCAD

1. AutoCAD
_$

Ctrl+Enter
EscShift+Esc_$


Enter

AutoCAD(C: AutoCAD)


_$(setq a 1 b 2 Ctrl+Enter
c 3 d 4) (setq e 5) Enter

4 4
5 5

_$

2.
_$Tab
Tab
Shift+Tab

3.
Visual LISP
Shift+F10

Visual LISPAutoCAD

Windows

AutoCAD

4.
.log

FileToggle Console Log


Toggle Console Log

4.4

1.
FileNew FileCtrl+N

2.
FileOpen FileCtrl+O

Open file to edit/view


Visual

LISP*

Visual LISP

3.
FileRepen

4.
Visual LISP

5. Visual LISPAutoLISP
AutoLISPAutoLISPVisual
LISPAutoLISP
1AutoLISP
FileLoad FiLe
Load lisp file
AutoLISP
a

b
3.2AutoCAD
AutoLISP

b
4-3AutoLISP

2Visual LISPAutoLISP
ToolsLoad Text in EditorTools

AutoLISP

3Visual LISPAutoLISP
AutoLISP
ToolsLoad SelectionTools

AutoLISP

5.1
FileEditSearch

StandardSearchTools

1.
5-1
Windows
Windows

5-1

2.
1
5-1

5-1

Ctrl +

Ctrl +

End

Home

PgDn

PgUp

Ctrl + End

Ctrl + Home

Ctrl + [

Ctrl + ]

5-2
5-2

Shift +

Shift +

Shift + End

Shift + Home

Shift + PgDn

Shift + PgUp

Ctrl + Shift +
Ctrl + Shift +
Ctrl + Shift + [
Ctrl + Shift + ]
Alt + Enter

3
5-3

5-3

Ctrl +

Shift +

Ctrl + E,E

4
Visual LISP
ToolsWindow AttributesConfigure CurrentTab
,5-4
5.4
5-4

Tab

Tab

Shift + Tab

Tab

Shift + Enter TAB

Ctrl + Enter

TAB

5.2
1.

Shift

5-2

2.

WindowsVisual LISP

12
5-2(a)
3

3.
Ctrl

5-2(b)

(a)

(b)

5-2

4.
SearchFind

5-3

5-3

1Find What
Find What

2Search
Current selection
Current file
Project

Files

Visual LISPLISP

3Direction
Down
Up

4Match whole word only


entVisual LISPentnext
Visual LISPententnext
5Match caseVisual LISP
carVisual LISPCarCAR
Visual LISPcarCARCar

6Mark instances

Find

F3

Visual LISP
5-4

5-4

5.
SearchReplace

5-5

5-5


1Find what
2Replace with
3Find

4Replace
Find
5Replace All

6.
5-6Visual LISP

32,

5-6

(1

SearchBookmarksToggle Bookmark

Alt + .

2
SearchBookmarksPrevious Bookmark

Ctrl + ,

.SearchBookmarksNext Bookmark,

Ctrl +.

3
Ctrl+Shift +,

Ctrl+Shift+.

Alt +.

5
SearchBookmarksClear All Bookmarks

5.3
AutoLISP

1. AutoLISP
ToolsEnvironment

OptionsVisual LISP Format


5-7

5-7


1Right Text Margin

20~200
2Narror style indentation

1~6
3Maximum wide-style car length

4Single-semicolon comment indentation

5Close Paren Style

Close at the same line


Close at the new line with inner indentation

Close at the new line with outer indentation

6Insert tabs

7Save formatting options in source file

8Insert fom-closing commment

9Form-closing comment prefix

10More option

11Revert to Defualt

ToolsSave Settings

2.

(1)
(2) ToolsFormat AutoLISP in EditorTools

ToolsFormat AutoLISP
in SelectionTools

Visual LISP

3.
Visual LISPCtrl + E
5-8
Tab,
Tab

MM/DD/YY
HH:MM:SS

5-8

4.
Ctrl+E 5-8
Save Block As File to write block to

File already

exists. Append selection to existing file ?

5.4
1.
AutoLISP

5-9

5-9

5-5
5-5

Ctrl+]

Ctrl+[

Ctrl+Shift+]

Ctrl+Shift+[


(setq alf1(cond

((and (> alf

90) (<= alf 270)) (- alf 180))

((> alf 270) (- alf 360))


((= alf -90) 90)
(t alf)
)
)

alflfCtrl+]
90 Ctrl+[ >
Ctrl+Shift+]90f

90)

Ctrl+Shift+[>> al

andndCtrl+]
90 Ctrl+[ and
Ctrl+Shift+] 90 d
(> alf

90) Ctrl+Shift+[and

an
cond on Ctrl+]
180)Ctrl+[cond
Ctrl+Shift+] 180))
nd

((and (> alf

90) (<=

alf

270)) (-

alf 180))

Ctrl+Shift+[ cond
co

2.
AutoLISP

3.
1Visual LISP


2

ToolsCheck Text in Editor

ToolsCheck Selection

Visual LISP5-10Build Output

5-10

2
SQRT
(sqrt)5-11(a)SQRT3
1IF
(if (> a b)55-11(b)IF
442

5-11(c)

(a)

(b)
5-11

(c)

6.1


Visual LISP

VisualLISP

6-1ViewView

VisualLISP

6-1 View

AutoCAD

6-2DebugDebug

6-2 Debug

Debug

6.2

DebugWatch Last Evaluation6-3

6-3

1.

2.
6-4

*obj*
'

6-4

3.

6-5

OK

6-5
2

6-6OK

3
Add Watch
OK

4.
"="A = 1

5.
6-6

ToolsText in Editor
Build Output"; Check done."

ToolsLoad Text in Editor


VisualLISP
AutoCAD""
(0,0)p1""
(100,100)p2

6-6P1P2P3P4

1DebugAdd Watch

p1

OKP2P3P4

26-7P1 = [0.0 0.0 0.0]


p2 = [100.0

0.0]p3 = [100.0 100.0 0.0]P4 = [nil

100.0]P4XX(car pl)
(car pl)carpl

PL = nilPL

p1

3plp1

6.3

6-1

(defun c:rectr(/ w h alf p1 p2 p3 p4)


(setq p1(getpoint "")

p3
p4

w (getdist p1 "")
h (getdist p1 ": ")
alf (getangle p1 ": ")
)

alf
p1

p2

(setq p2(polar p1 alf w))


(setq p3(polar p2 (+ alf (* 0.5 pi)) h))

(setq p4(polar p3 (+ alf pi) w))

(command "pline" p1 p2 p3 p4 "c")


(princ)

p3

p4
alf

p2

p1

1.
1FileOpen File
[6-1]
DebugAdd Watch
w
halfp1p2p3p4ToolsLoad Text in Editor

2DebugStop Once
3
rect3

AutoCADAutoCADCommand

VisualLISP
nil(defun
Debug Step Into F8

(setq p1

(getpoint "

")"I""
"

AutoCAD"
" (100,80)

VisualLISP(getpoint "
")"
I "" "

(getdist p1 "")

"I"""
p1=[100.0

80.0

0.0]

AutoCAD200150
30

alf

(setq p3(polar p2 (+ alf (* 0.5 pi)) h))

AutoCAD

5 (getangl

p1 "

: ")"
: ""; error: no function definition:
GETANGLGETANGL"

" FIND "FindWhat

" GETANGL" " Find" getangl


getangle

2.
1

6-1wh
alfp1p2p3p4DebugAnimate
AutoCAD"Command""rect3"Visua
lLISP
"I"""

"; error: no function definition:

"

2
ToolsEnvironmant OptionsGeneral
Options 6-7General Options
DiagnosticAnimation
delay

6-7

6.4
AutoLISPLISP
LISP

AutoLISP
VisualLISP

VisualLISP

Break loop

VisualLISP_$

_1_$
AutoCAD

1.

1Stop Once
2Debug on Entry
3
4
5Step IntoStep Over
Step Out

setq

2.
Break On Error

DebugReset to
Top Level

DebugQuit Current

6.5
,

1.
1/
VisualLISP

DebugToggle Breakpoint

F9

Toggle Breakpoint
Visual

LISP

DebugClear All Breakpoints

2
VisualLISP
ToolsWindow AttributesConfigure Current
Window AttributesWINDOW-TEXT:BPT-ACTIVE


Breakpoints service6-8

6-8

Disable
6-9Enable

4
ViewBreakpoints Window6-9

6-9

6-1.lsp3
6-2.lsp2
0"+"
"- "
Delete all
ShowDelete
Edit6-9

2.

Debug
ContinueCtrl+F8

Quit CurrentCtrl+Q

Reset to Top LevelCtrl+R

3.
6-2 6-10p0dbt1alf

6-10

(defun c:tuxing (/ p0 alf d b t1 r l b1 sit p1 p2 p3 p4 p5)


(setq p0

(getpoint "\nEnter P0: "))

(setq d

(getdist p0 "\nEnter d: "))

(setq b

(getdist p0 "\nEnter b: "))

(setq tl

(getdist p0 "\nEnter t1: ")) ;tlt1

(setq alf (getangle p0 "\nEnter alf: ")) 1

(setq r (* 0.5 d) bl (* 0.5 b))


(setq l (sqrt (- (* r r) (* b1 b1))))
(setq sit (tan b1 l))

;tanatan

(setq p1 (polar p0 (+ alf sit) r))


(setq p2 (polar p0 (+ pi alf) r))

(setq p3 (polar p0 (- alf sit) r))


(setq p4 (polar p3 (+ pi alf) (- (+ r l) t1)))
(setq p5 (polar p1 (+ alf pi) (- (+ r l) t1)))
(command "pline" p1 "a" "s" p2 p3 "l" p4 p5 "c")
)

FileOpen File6-2

DebugAdd Watch

p0dbt1alfrlb1sitp1p2p3p4p5

AutoCADCommand:

TUXING";error: bad argument

type: numberp: nil


"
6DebugToggle
BreakpointF9

Command:TUXING

p0dbt1alf

15get
p0 d b alf

T1=nil setq tl (getdist p0 "\nEnter t1:


")t1tl

Command:TUXING

p01

t1

"; error: no

function definition: TANTAN"


"tan"
"atan" 1
1

Command:TUXING
p0
6-10

6-10

DebugBreak On Error
"tan"

CommandTUXING

"Esc"

6.6

1.
VisualLISPAutoCAD
AutoCAD
DebugTrace Command Command
TUXING6-11"Trace"
AutoCAD

6-11AutoCAD

2.
"Error Trace"
6-13

6-3"Error Trace"
6-3
2

b
4ac
x
2a

a=0

(defun roots(a b c / t1 t2 x1 x2) t1t2x1x2


(if (/= a 0)
(progn

(setq t1 (- (* b b) (* 4 a c)))
(if (>= t1 0.0)
(progn
(setq t2 (sqrt t1))
(setq x1 (/ (+ -b t2) (* 2 a)))
(setq x2 (/ (- -b t2) (* 2 a)))
(print (list x1 x2))
)
(print "\n.")
)
)
(print "\n.")

)
(princ)

FileOpen File6-3

Visual LISP Console()_$

(ROOTS 1 5 6)""6-12

6-12
ViewError TraceCtrl+Shift+R6-13

6-13

1"<1>:ERROR BREAK"
2"[2][+ nil 1.0]"1.0
26-14
"Call point source"(+ -b t2)
-b-bnil
-bb(- t2 b)
(- -b t2)(- 0 b t2)
(3.0 2.0)

3.

6-4
VisualLISP6

6-4
stack-tracingindexval
maxval indexval
maxvalindexvalst5stack-tracing

(defun stack-tracing (indexval maxval)


(princ "\n = ")
(princ indexval)
(if (< indexval maxval)

(stack-tracing (1+ indexval) maxval)


(princ "\n") ;

(stack-tracing 1 5)

6-14

6-14

"[]""<>"

Lambda


[] [

...]

6-1426stack-tracing

[2]STACK-TRACING 5 5
"[2]""STACK-TRACING"


<> :

VisualLISP

6-1
6-1

:ACAD-REQUEST

AutoCAD

:DCL-ACTION

AutoCAD :DCL-ACTION

:INSPECT-EVAL

:INSPECT-VERBOSE

:TOP-COMMAND

VisualLISP

:USER-INPUT

:WATCH-EVAL

6-148

<8>:USER-INPUT (stack-tracing 1 5)
(stack-tracing 1 5)
6-2

6-26-2

:ACMD-CALLBACK

AutoCAD

:AFTER-EXP

Step IntoStep Over

:ARQ-SUBR-CALLBACK

AutoCADVisualLISP

:AXVLO-IO-CALLBACK
:DWF:DWG
:BEFORE-EXP
:BREAK-POINT
:ENTRY-NAMESPACE

DWGDWFVLA
Step Into Step Over

VLX

:ERROR-BREAK

Show Message

:FUNCTION-ENTRY

Pause

:KBD-BREAK
:PROTECT-ASSIGN

:REACTOR-CALLBACK
:READ-ERROR
:SYNTAX-ERROR

Show Message
Inspect
:PROTECT-ASSIGN

Show Message

AutoLISP

6-141

<1>: BREAK-POINT


VisualLISP

Lambda lambdaVisualLISP

foreachrepeatVisualLISP

<>[FOREACHREPEAT ]
l FOREACH foreach
(foreach n '(a b c) (print n))
(print n)ViewTrace stack
6-15

6-15foreach
<1>AFTER-EXP[1]6-2
,AFTER-EXP
Step IntoStep Over
[2][FOREACH][2][FOREACH]

l REPEAT repeat
(setq i 0)
(repeat 10
(princ (1+ i))
)

(1+ i)ViewTrace stack


6-16

6-16repeat

ifcondsetq
VisualLISP

6-14

6-14stack-tracing

8<8>:USER-INPUT (stack-tracing 1 5)
(stack-tracing 1 5)

7[7](USUBR@034086e0-top->)

6[6](stack-tracing 1 5)
indexval1maxval5
5[5](stack-tracing 2 5)
indexval2maxval5
4[4](stack-tracing 3 5)
indexval3maxval5
3[3](stack-tracing 4 5)
indexval4maxval5
2[2](stack-tracing 5 5)
indexval5maxval5
1<1>: BREAK-POINT

6.7
1.

2.

6-17

6-17

VisualLISP

2Name
3Value

4Flags
TraceTraceTrace

Protect Assign

AutoLISP
pisetq
Debug on Entry

Export to AutoCAD
ObjectARX

3.

1
ViewSymbol ServiceDebug
2

6-18

OK6-17

6-18

4.

(setq a 1)
(princ a)

"Value"a1

2OK

a2

5.

(setq a+ b c) b

b
"Flags"
"Protect Assign"OKb
b
6-19""""
b

6-19
Protect Assign

6.
6-4VisualLISP
stack-tracing

"Flags""Debug on Entry "


OKstack-tracing

6.8
1.
AutoCAD
AutoCADAutoLISPAutoCAD
ActiveX

2.

6-20
6-20

1
2

"[ ]"""
"{ }"

3.
AutoLISP
VisualLISPViewInspectDebug

InspectSymbol Service

VisualLISP6-21

6-21
VisualLISP15

4.

INT

ASCII256256

REAL

STRING

LIST ()

6-22
LIST()
dotted pairscarcdr
(cons 8 "A") 6-23

6-22

6-23

FILE
6-24
namemode

id,position
eof
SUBR

SUBRSUBRUSUBR
SUBR
6-25

6-24

6-25

USUBR

6-26

6-26

6.9 AutoCAD

AutoCADAutoCAD

1.
ViewBrowse Drawing DatabaseBrowse All Entities
6-27aAutoCAD

6-27 AutoCAD

"Inspect"
6-27b<CIRCLE>
ACAD CIRCLE
<Entity name: 7ef4fe90>,

PrintCopyLogandUpdate

l ModifyAutoCAD DDMODIFY

l Inspect Raw Dataentget


6-28
l Inspect Next Ent
l Inquire Extended Dataregapp

6-28

ToolsEnvironment OptionsGeneral Options1322General Options


DiagnosticInspect Drawing Objects

6-28

2.
ViewBrowse Drawing DatabaseBrowse Tables
6-29a

(a)

(b)
6-29

(c)


<Layer>6-29b

<0>
6-29c
"0"

3.
ViewBrowse Drawing DatabaseBrowse Blocks

6-30(a)AutoCAD
b3Inspect
6-30b

Parts6-30c

(a)

(b)

(c)

6-30

LINECIRCLE

4.
ViewBrowse Drawing DatabaseBrowse Selection
VisualLISPAutoCAD"Select objects:"
VisualLISP6-31

6-31
Inspect

AotuCADAutoLISP
AutoLISP

AutoLISP

".fas"

Visual LISP".vlx"
AutoLISPdclvba

Visual LISP vlisp-compile


AutoLISP " "
AutoLISP".fas" ".vlx"

7.1 Visual LISP_compile

(vlisp-compile 'mode "filename" [out-filename])


modefilenameout-filename
".fas"

1.
mode

1st

2lsm

3lsa

2. LSP
AutoCAD
AutoCAD ToolsOptions Files Support File
Search Path
"d:\user"vlisp-compile
'st "sample.lsp")D"\user1""sample.lsp"
"d:\user"

(vlisp-compile 'st "d:\\user\\example.lsp") (vlisp-compile 'st "d:/user/


example.lsp")

Visual LISP".lsp"

3.

".fas"

(vlisp-compile 'st "d:/user/example.lsp")"d:/user/"


"example.fas"
Visual LISP

AutoCAD"d:\autocad2006\"
(vlisp-compile 'st "sample.lsp" " sample.fas")sample.fas
"d:\autocad2006\"

(vlisp-compile 'st "d:/user1/example1" "d:/user2/example2")

4.
AutoLISPexample1.lspduser1
screw
example2duser2
1AutoCADCommand_$ vlisp-compile
(vlisp-compile 'st "d:/user1/example1" "d:/user2/example2")
duser1LSP"example1.lsp"
duser2"example2.fas"
2 Build Output
7-1

AutoCAD


AutoLISP

7-1

5.
".fas"".vlx"
Visual LISPAutoCAD
AutoLISP AutoCADToolsLoad Application
ToolsAutoLISPLoadVisual LISPFileLoad File

AutoLISP
1Visual LISPLSP
(load "d:/user2/example.fas")
load ".vlx"
".vlx"load ".fas"
".fas"load".lsp "

Visual LISP"File""Load File""Load

lisp file"
2Visual LISP
LISPAutoCAD"C"

AutoCAD
LISPAutoCADAutoCAD
3 AutoLISP

Visual LISPAutoLISP vla-


vlax-vlr-AutoCAD
vl-load-comAutoLISP

(vl-load-com)

7.2
AutoLISPAutoLISP

".vlx"VLX

VLX".fas"
AutoLISP ".prv" Visual
LISP

gear.lsp LISP
gear.dclduser1

"chilun" Duser2

(1)
Visual LISPFileMake AplicationNew Aplication
WizardVisual LISP7-2

7-2

(2)
SimpleExpert
LISPLISPVisual LISP

LISPSimple
ExpertNext7-3

7-3

(3)
7-3Application Location
Browse

d:/user2 Application Name


chilun,d:/user2/chilun.vlx
chilun.prv

7-3

Next
7-4
Separate
Namespace
Next7-5
LISP

7-4

5LISP
LISPAutoLISPAutoLISP(FAS)Visual
LISP7-5LISP
LISP

7-5LISP
Lisp source filesAdd7-6
lisp

6lisp
Windows7-6
gear.lsp
7-7Lisp
Add

7-6lisp

AutoLISPVisual LISPVLX
FASFAS
PRJ
VLX

7-7Lisp
Remove

Remove

"LISP Files to Include"

Top
Up
Down
Bottom

Next

7-8

7-8

DCLDVB

LISPVLX

7-9DCL

7-8DCL filesAdd
7-9DCLgear.dcl
DCL710

7-10
Next7-11

8
7-11Standard

Optimize and Link

7-11

Next7-12
/

9
Back
Finish

7-12/

d:\user2
chilun.prvchilun.vlxgear.faschilun.prv

Visual LISP,gear.vlx
gear.fasgear.lsp
gear.vlxgear.fas"Command"
GEAR
AutoLISP

(2)Simple
478

7.3 LISP
AutoLISPLISP

Visual LISP
7.3.1
LISP
LISP

LISP

LISP

7-1
pclmaxlminalf

lmin7-13

a7-13b

L1
L2

sin(120 alf ) sin(60)

7-13

file1.lsp
r-hexagonAutoCADfile2.lsp
hexagonhexagond
user1

file1.lsp

(defun c:r-hexagon( / pc lmax lmin alf )


(setvar "cmdecho" 0) ;
(setvar "blipmode" 0) ;
(setvar "osmode" 0) ;

(setq pc(getpoint "\n:"))


(setq lmax(getdist pc "\n:"))
(setq lmin(getdist pc "\n:"))
(setq alf(getangle pc "\n:"))

(hexagon pc lmax lmin 0.0) ;


(princ) ;
)

file2.lsp
(defun hexagon (pc l lmin phi ) ;phi
(command "pline" (polar pc phi l)
(polar pc (+ phi (/ pi 3.0 )) l)
(polar pc (+ phi (/ pi 1.5 )) l)

(polar pc (+ phi pi) l)


(polar pc (+ phi (/ pi 0.75)) l)

(polar pc (+ phi (/ pi 0.6 )) l)


"c"

)
(if (>= l lmin)

(progn
(setq l(/ l (+ (cos alf) (* (sin alf) 0.5773503))));

(setq phi (+ phi alf)) ;


(hexagon pc l lmin phi) ;

)
))

7.3.2
1.
ProjectNew project7-14

rhduser2

7-14

2. LISP
7-147-15

LISP

7-15

7-15 LISP
LISP

LISP

TopUpDownBottom
LISP

7-15

LISPduser1
user1LISPfile1file2
file1file2rh
7-16
rhduser2
rh.prj

7.3.3

LISP

7-16
5
7-15

.fasLISP
7-17""

""LISP
.fas
file1.lspfile2.lsp7-17

""
file1.fas file2. fas AutoCAD "Command" rhexagon

LISP
.fas

LISP

7-18

7-18

Edit

Add File
Remove file

Load.fasLISP
Load sourceLISP
Check syntax
Touch""""

Arrange files
Multiple Selection
""
[Un]Select all

Close project
Save proct as

7.3.4

7-19
ProjectProject
Find WhatFind
7-20

7-19

ProjectrhFind What
hexagonFind7-20
file2.lspfile1.lsphexagon4

hexagon

7-20

7.3.5

5LISPLISP
LISPVisual LISP

7-21LISP
VisualLISP projectAddAdd
VisualLISP project files d user2
rh.prj7-21Next
duser1file1.lspfile2.lsp

7-21VisualLISP projectLISP

7.3.6

Visual LISP
7-15
7-22

7-22

1. Compilation Mode

l Standar

l Optimize

2. Merge file mode

l One module for each file:LISP.fas

l Single module for all:.fas

3. Link mode
3

l Do Not Link:

l Link:

l Internal:

AutoCAD

4. Message mode
3
Fatal errors

Errors and warnings


Full reports

5. Localize variables
Optimize

6. Safe optimize

Optimize

7. Fas directory.fas
.fas

8. Tmp directory

9. Edit Global Declarations


(.gld)
Visual LISP

8.1

AutoCAD

command
setvar

1.

420,297

A3
1command

0,0

(command "limits" "0,0" "420,297")

(command "limits"

'(0

0)

(command "limits"

(list 0

'(420 297))
0)

(list 420 297))

p1p2

(command "limits" p1 p2)

2setvar
limminlimmax
setvar

(setvar "limmin" '(0 0))


(setvar "limmin" (list 0 0))

(setvar "limmin" "0,0")


(setvar "limmin" p1)

(setvar "limmax" '(420 297))


(setvar "limmax" (list 420 297))
(setvar "limmax" "420,297")
(setvar "limmax" p2)

2.
3
2X0

1command
(command "units" 2 3 1 2 0 "N")
command
unitsAutoCAD

2
33
1

22
0X0
N

2setvar

(setvar "lunits" 2)
(setvar "luprec" 3) 3
(setvar "aunits" 1)
(setvar "auprec" 2) 2
(setvar "angbase" 0.0) X0

(setvar "angdir" 0)

3.

osmode
0 NONe
1 ENDpoint

2 MIDpoint
4 CENter

ENDpoint

MIDpoint

CENter

8 NODe point

16 QUAdrant
32 INTersection

NODe
QUAdrant
INTersection
64 INSertion
128 PERpendicular

INSertion

PERpendicular

256TANgent

512 NEArest
1024QUIck

2048APParent Intersection
4096EXTension

8192PARallel

TANgent APParent Intersection

EXTension

PARallel

1command
(command "osnap" "endpoint,midpoint,center")

(command "osnap" "none")


2setvar
(setvar "osmode" 7)7
(setvar "osmode" 0)
osmode0
osmode1
pp
pp
setvarosmode0

4. AutoCAD
AutoCAD
commandline

setvarAutoCAD

(setvar "cmdecho" 0)
cmdecho1
AutoCAD0
AutoLISPcmdecho0

8.2
1.
zhongxincenter0.2
command
(command "layer" "Make" "zhongxin" "Color" 1 "zhongxin"
"Center" "zhongxin" "LWeight" 0.2 "zhongxin" "")

"Ltype"

layer[?/Make/Set/New/ON
/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/state]

MakeColorLtypeLWeightMCLLW

(command "layer" "M" "zhongxin" "C" 1 "zhongxin"


"zhongxin" "LW" 0.2 "zhongxin" "")

"L" "Center"

ColorLtype

(command "layer" "M" "zhongxin" "C" 1 "" "L" "Center" ""


"LW" 0.2 "" "")

(command "layer" "M" "cuxian" "")


cuxian 7 /
continuous

(command "layer" "M" "cuxian" "")


(command "layer" "S" "cuxian" "")

2.
1command
(command "color" 3)
(command "color" "green")

2setvar
(setvar "cecolor" "2")

(setvar cecolor yellow)

3.
1command
(command "linetype" "s" "centerset" "")

2setvar
(setvar "celtype" "dashed")

4.
continuous


1command
(command "ltscale" 0.5)
2setvar
(setvar "ltscale" 0.5)

5.
1command

(command "lweight" 0.5)0.5


2setvar
celweight
10.5

(setvar "celweight" 50)

8-1 8-1
pbLalf
cuxian
zhongxincenter

1.
(defun c:pingjian(/ p b l alf r l1 p1 p2 p3 p4 p5 p6
p7 p8 p9 p10)

(setvar "osmode" 0)
(setvar "cmdecho" 0)
(command"layer" "make" "cuxian" "c" 5 "cuxian" "")
cuxian

(setq p(getpoint ""))


p
(setq b(getdist p ""))
b
(setq l(getdist p ""))
l

(setq alf(getangle p ""))


alf
(setq r (* 0.5 b) l1(- l b))rl1b
l
(setq p1 (polar p (+ alf (* 0.5 pi)) r))p1-p4
4
(setq p2 (polar p1 alf l1))
(setq p3 (polar p2 (+ alf (* 1.5 pi)) b))
(setq p4 (polar p1 (+ alf (* 1.5 pi)) b))

(command "pline" p1 "width" 0.6 0.6 p2 "arc" p3


"line" p4 "arc" "close")
(command "layer" "m" "zhongxin" "c" 1 "" "l" "center"
"" "")
zhongxinxian

(setvar "ltscale" 0.5)

(setq p5 (polar p1 (+ alf (* 0.5 pi)) 5))


(setq p6 (polar p2 (+ alf (* 0.5 pi)) 5))
(setq p7 (polar p3 (+ alf (* 1.5 pi)) 5))
(setq p8 (polar p4 (+ alf (* 1.5 pi)) 5))
(setq p9 (polar p (+ alf pi) (+ r 8)))
(setq p10 (polar p alf (+ (- l r) 8)))
(command "line" p5 p8 "")

(command "line" p6 p7 "")


(command "line" p9 p10 "")

2.
1AutoCADdefun
C:
2AutoCADpb
l

33setvarcmdecho
get

45getpoint

100,50""

56getdist

pp

68getangle

X
p
pX
180
3.14159
7 14 command "pline"
AutoCAD

(command "pline" p1 "w" 0.6 0.6 p2 "a" p3 "l" p4 "a"


"cl") "w" "a" "l" "cl" pline
"width""arc""line""close"
8154

(defun tuceng(name color ltyle)

(command "layer"
""))

"m" name "c" color name "l" ltype

name
color0-255
ltypeAutoCADdashedcenter

4
(tuceng "cuxian" 3 "")
15
(tuceng "zhongxin" 1 "center")
9AutoCADCommand
pingjian

8.3
StyleAutoCAD.shxwindows
.ttf
standard AutoCAD
txt.shxstandard
command
Style
1AutoCAD
(command "style" " ziyang1" " complex" "0.0" "1.0"
"0.0" "N" "N" "N" )

style
ziyang1

complexAutoCADcomplex.shx
0.00
text

1.01.03:2
0.0obliquing angle

N(backwards)Y
N(upside-down)Y

(command "style" "ziyang" "complex" "" "" "" "" "" "" )

2Windowsstfanso.ttf
hanzi1
(command "style" " hanzi1" "stfangso.ttf" "" "" "" ""
"")

(command "style" "hanzi2" "" "" "" "" "" "")

3big font
Windows
AutoCADc
%%d%%p

(command "style" "hanzi3" "gbcbig" "" "" "" "" "")


gbcbiggbcbig.shx
4

(command "style" "hanzi4" "complex,gbcbig" "" "" "" ""


"")

8-2A4

GB/T 14689-1993GB/T10609-1989

1. A4
(defun c:a4( /
a4

v1 v2 v3 ljmch cl shl bl)

(setq v1(getvar "osmode"))


v1
(setq v2(getvar "cmdecho"))
v2

(setq v3(getvar "blipmode"))


v3
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)

(setq ljmch(getstring "\n"))


ljmch
(setq cl(getstring "\n"))
cl
(setq shl(getint "\n"))
shl
(setq shl(itoa shl))shl
(setq bl(getstring "\n"))
bl

(command "style" "hz" "gbcbig" "" "" "" "" "" "")
hz
(command "layer" "m" "xixian" "c" "1" """")
xixian
(command "limits" "0,0" "210,297")

(command "line" "0,0" "210,0" "210,297" "0,297" "c")


A4
(command "layer" "m" "cuxian" "c" "7" "" "lw"
"" "");cuxian

0.6

(command "line" "25,5" "205,5" "205,292" "25,292"


"c")
(command "line" "85,5" "85,27" "205,27" "")

(command "line" "85,13" "205,13" "")

(command "line" "100,13" "100,27" "")


(command "line" "120,13" "120,27" "")

(command "line" "132,5" "132,27" "")


(command "line" "162,5" "162,13" "")

(command "line" "180,5" "180,27" "")


(command "layer" "m" "xixian" "")
(command "line" "85,20" "132,20" "")

(command "layer" "m" "wenzi" "c" "5" "" "")


wenzi
(command "text" "m" (list 108.5 9) 5 0 "
")
(command "text" "m" (list 147 9) 5 0 (strcat "
" cl))
(command "text" "m" (list 171 9) 5 0 (strcat "
" shl))

(command "text" "m" (list 192.5 9) 5 0 (strcat "


" bl))

(command "text" "m" (list 92.5 23.5) 5 0 " ")


(command "text" "m" (list 92.5 16.5) 5 0 " ")
(command "text" "m" (list 156 20) 10 0 ljmch)
(setvar "osmode")
(setvar "cmdecho" v2)

(setvar "blipmode" v3)


(princ)
)

2.
12-4getvarosmode
v1v2v3

25-7setvarosmode

311(setq shl(itoa shl))shl

430"text""m"

531strcat
" ""40Cr",
" 40Cr "cl))
637-39setvarosmode

740(princ)

8GB/T 14689-1993
GB/T10609-1989
9AutoCADCommand
A4

8.4
1.

1p12p2
p3

p3
p1p2
(setq p1 '(10 10) p2 '(50 20) p3 '(30 25))
(command "line" p1 p2 "")

1
(command "dimlinear" p1 p2 "h" p3)

dimlinearcommand
p1p212
h(v)
(Rotated)
p3
"x,y"xyp3
"30,25"2p2

"@x,y"@xp2X
yp2Yh
xx

(command "dimlinear" p1 p2 "h" p3)


(command "dimlinear" p1 p2 "h" "30,25")

(command "dimlinear" p1 p2 "h" "@-20,5")


3a

"h""v"
(setq p1 '(10 10) p2 '(40 25) p3 '(45 25))

(command "line" p1 p2 "" )


(command "dimlinear" p1 p2 "v" p3 )
b

2
p3p1p2
p3Xp1p2Xp3Yp1p2
Y
3"h"p3X
p1p2X
(command "dimlinear" p1 p2

'(55 15))

(command "dimlinear" p1 p2

"55,15")

(command "dimlinear" p1 p2

"@5,-5")

2.

(command "dimaligned" p1 p2 p3)


(command "dimaligned" p1 p2 "35,25")
(command "dimaligned" p1 p2 "@-13.04,2.64")

3.

""

(setq pc '(100 100) r 12.5 p1 (polar pc 0 12.5) p2


'(105 105))
(command "circle" pc r)


(command "dimdiameter" p1 p2)
(command "dimdiameter" p1 "105,105")
(command "dimdiameter" p1 "@-7.5,5")
p1p2
"105,105"
"@-7.5,5"p1XY

""

(command "dimradius" p2 p4)


(command "dimradius" p2 "105,105")
(command "dimradius" p2 "@-7.5,5")
p2
p4
"105,105"
"@-7.5,5"
p2XY

"R"

4.

""

(command "dimangular" p1 p3 p4)

(command "dimangular" p1 p3 "40,14")


(command "dimangular" p1 p3 "@0,-6")
p1p3
p4"40,14"
"@0,-6"p3X
Y
""

45

(command "dimangular" p1 p3 "A" 0.01 p4)


(command "dimangular" p1 p3 "A" 0.01 "40,14")
(command "dimangular" p1 p3 "A" 0.01 "@0,-6")
"A"
AutoCAD00.01

5.
1

MetricEnglish
2.5
0.18
2

AutoCAD200464
dimscale1

dimtad0(OFF)
1

dimtih0
0(OFF)

dimtoh0
0(OFF)

dimtix0
0

dimtofl0
1

dimzin810.0000
1012.500012.58
dimdsep
,.
dimlfac
1.02100
200200
dimtsz0
0

3
setvar
command

(setvar "ltscale" 2) 2
(setvar "dimtad" 1)
(setvar "dimtih" 0)

(setvar "dimtoh" 0)

(setvar "dimtix" 1)
(setvar "dimtofl" 1)

(setvar "dimzin" 8) 0
(setvar "dimdsep" ".")"."

(setvar "dimlfac" 2) 2
(setvar "dimtsz" 2.5)

(command "ltscale" 1) 1
(command "dimtad" 0)
(command "dimdsep" ".") "."

6.
AutoCAD

"text""t"

2
"text"
"t"

(command "dimlinear" p1 p2 "h" "t" "%%c50" p3)a

(command "dimaligned" p1 p2 "t" "60cm" p3)b


(command "dimdiameter" p1 "t" "2X%%c50" p2)c

(command "dimradius" p2 "t" "R10" p4)d


(command "dimangular" p1 p3 "A" 0.01
p4)e

"t" "45.5%%d"

8-11240
460405
"text""t"

"<>"
<>

60460240540
(command "dimlinear" p1 p2 p3)
(command "dimlinear" p1 p4 "t" "4X60=<>" p5)
(command "dimdiameter" p6 "t" 5X<>" p7)


(command "dimdiameter" p1 "t" "4X<>%%c45" p2)
(command "dimdiameter" p3 "t" "<>10" p4)

8.5 AutoCAD
1.
1
41
AutoCADcopy

24
4
linearc
AutoCADfillet
4

3AutoCAD
13
p1p2
p4p3p3p5p5p6
AutoCADtrimtrim

8-3 4

3
1
(command "layer" "m" "zhongxin" "l" "center" "" "")

(command "line" "-5,0" "5,0" "")


(command "line" "0,-5" "0,5" "")
(command "layer" "m" "cuxian" "lw" 0.3 "" "")
(command "circle" "0,0" 3)
(command "layer" "m" "xixian" "")

(command "arc" "-3.5,0" "0,3.5" "0,-3.5")


(command "zoom" "a")

AutoCADcopy3

(command "copy" "w" "-5,-5" "5,5" "" "m" "0,0" "12,0"


"24,0" "36,0" "")

(command "copy" "w" "-5,-5" "5,5" "" "m" "0,0"


"12,0" "24,0" "36,0" "")

copycommand

w
-5,-5
5,5
""
m

0,0
12,024,036,0
""

8-4 4

(command "layer" "m" "cuxian" "")

(command "line" "-7,-6" "43,-6" "43,6" "-7,6" "c")


(command "zoom" "e")

4
(command "fillet" "r" 1.5)

(command "fillet" "-7,0" "18,-6")


(command "fillet" "18,-6" "43,0")

(command "fillet" "43,0" "18,6")


(command "fillet" "18,6" "-7,0")


"p"4

(command "layer" "m" "cuxian" "")


(command "rectangle" "-7,-6" "43,6")
(command "fillet" "r" 1.5)
(command "fillet" "p" "18,-6")

8-58-17
13
(command "circle" "0,0" 40)
(command "line" "50,11" "31,11" "31,-11" "50,-11" "")

AutoCADtrim

(command zoom e)
(command "trim" "All" "" "40,0" "50,11" "50,-11" "")


trimcommand
All
""
40,0

50,1150,-11

""

2.
1

zoompan

setvarpickbox
050
3offfreeze

4
13

8.6
AutoCADbhatchhatch
bhatch
hatch

(command "layer" "m" "poumian" "")


(command "bhatch" "p" "ansi31" 1.5 0 "0,0" "")

bhatch
ppick

ansi31
1.5
0

0,0
""

(command "hatch" "ansi31" 1.5 0 "w" "-40,-40" "40,40"


"")

hatch

w
-40,-4040,40
""

8.7
y=f(x)
Xmin x Xmax

y=f(x)

XminXmax Delta
n=(Xmax-Xmin)/Delta
Delta=(Xmax-Xmin)/n
X1=Xmin,Y1=f(X1)

X1 < Xmax ?

X2=X1+delta,Y2=f(X2)
X1Y1X2Y2
X1=X2,Y1=Y2

8-6
8-19
x = r(cos + sin)
y = r(sin - cos)

1.
(defun c:inv(/ p0 phi phimax phimin dphi n x0 y0 x1 y1 x2 y2)

(setq p0(getpoint "\n"))


(setq r(getdist p0 "\n"))
(command "circle" p0 r)

(setq phimin(getreal "\n"))


(setq phimax(getreal "\n"))
(setq dphi(getreal "\n"))

(setq n(/ (- phimax phimin) dphi))n


(setq dphi(/ (- phimax phimin) n))dphi

(setq x0(car p0) y0(cadr p0))x0y0


(setq phi phimin)
(setq x1(+ x0(* r(+ (cos phi)(* phi(sin phi))))))x1=
x0 + r(cos + sin)
(setq y1(+ y0(* r(- (sin phi)(* phi(cos phi))))))y1= y0 + r(sin
- cos)

(while (< phi phimax) while


(setq phi(+ phi dphi))
(setq x2(+ x0(* r(+ (cos phi)(* phi(sin phi))))))
(setq y2(+ y0(* r(- (sin phi)(* phi(cos phi))))))

(command "line" (list x1 y1) (list x2 y2) "")


(setq x1 x2 y1 y2)
) while
)

8.8

AutoCADAutoLISP

8-7

1
p0alfGB65-85
dlk
dknt

p0alfdl
d dk=1.5d k=0.6d n=0.2d
t=0.25d

2
12
p1p2p20
plpr

3p0alf
p1p0alf+0.5 0.425d
p3p0alf+0.5 0.5d

(defun c:screw( / p0 p1 p2 p3 p4 p5 p6 p7 p8
p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20
d l alf dk k n tt d1 dk1 n1 d2 l1)

(setq p0 (getpoint "\n"))


(setq d (getdist p0 "\n"))
(setq l (getdist p0 "\n"))
(setq alf (getangle p0 "\n"))
(setq dk (* 1.5 d) k (* 0.6 d) n (* 0.2 d) tt
d))

(* 0.25

(setq d1 (* 0.5 d) dk1 (* 0.5 dk) n1 (* 0.5 n) d2 (*


0.425 d))

(setq p1 (polar p0 (+ alf (* 0.5 pi)) d2)


(+ alf (* -0.5 pi))d2))

p2 (polar p0

(setq p3 (polar p0 (+ alf (* 0.5 pi)) d1)


(+ alf (* -0.5 pi))d1))

p4 (polar p0

(setq p5 (polar p0(+ alf (* 0.5 pi)) dk1)


(+ alf (* -0.5 pi))dk1))

p6 (polar p0

(setq p7 (polar p5 (+ alf pi) k)


k))

p8 (polar p6 (+ alf pi)

(setq p9 (polar p7 (+ alf (* -0.5 pi)) (- dk1 n1))


(polar p8 (+ alf (* 0.5 pi)) (- dk1 n1)))
(setq p11 (polar p9 alf tt)
(setq p15 (polar p1 alf l)
(setq p17(polar p3 alf l)

p12 (polar p10 alf tt))


p16 (polar p2 alf l))
p18 (polar p4 alf l))

p10

(setq pl (polar p0 (+ alf pi) (+ k 4))


alf (+ l 5)))

pr

(polar p0

(command "linetype" "s" "center" "")


(command "lweight" 0)
(command "line" pl pr "")
(command "linetype" "s" "bylayer" "")
(command "lweight" 0.6)

(command "line" p5 p7 p9 p11 p12 p10 p8 p6 "c")


(command "line" p3 p17 p18 p4 "")

(if (> l (* 2 d))


(progn (setq l1 (- l
(* 2 d)))2
2

(setq p19 (polar p3 alf l1)

p20 (polar p4 alf l1))

(setq p13 (polar p1 alf l1) p14 (polar p2 alf l1))


(command "line" p19 p20 "")

)
(setq p13 p1 p14

p2) 2

)
(command "lweight" 0)

(command "line" p13 p15 "")


(command "line" p14 p16 "")
(command "lweight" "bylayer")
)

8-8
AutoCADLINECIRCLETEXT
a

TEXT

1.

p0alf
bh1
shGB1031-83
h1h
h1 = 1.4 * h /cos30
h1=1.61658 hp0halfs

2.
3
21
p1p2p3p4
p0alf
h

3.

3.56.3
3.5h6.3s

4. p0alf
osnap
8-25

(setq p01(osnap p0 "nea"))


osnapp0
p01
p0p01

(setq alf1(angle p01 p0))

anglep01p0Xalf1
alf10.5Xalf
p0p01p0
alf
p0
osnapnil
p0alf0

p0

4.
(defun c:rough(/ v1 v2 p0 p01 p1 p2 p3 p4 h h1 s al alf
alf1)
(setq v1(getvar "cmdecho"))

(setq v2(getvar "blipmode"))

(setvar "cmdecho" 0)
(setq p0(getpoint ": "))

(setq p01(osnap p0 "nea"))


(setq h(getdist p0 "\n<3.5>: "))
(if (not h) (setq h 3.5)) h
h=3.5
(setq h1(* h 1.61658))

(if p01
(progn
(setq alf1(angle p01 p0))
(setq p0 p01)p0=p01
(setq alf(- alf1 (* 0.5 pi))) alf = alf1 0.5
)

(progn
(setq alf(getangle p0 "\n<0>: "))
(if (not alf) (setq alf 0.0))
) alfalf=0.0
)

(setq a1(+ alf (/ pi 3)))


(setq p1(polar p0 a1 (* 2 h1)))
(setq p2(polar p0 a1 h1))
(setq a1(+ alf (/ pi 1.5)))
(setq p3(polar p0 a1 h1))
(setq a1(+ alf (* 0.5 pi)))
(setq p4(polar p0 a1 (* 1.4 h1)))
(setq s(getstring "\n<6.3>: "))
(if (= 0 (strlen s)) (setq s "6.3"))
0s="6.3"
(setq alf(/ (* alf 180) pi))

360

(setq alf(cond ((and (> alf


180))

90) (<= alf 270)) (- alf

((> alf 270) (- alf 360))


((= alf -90) 90)

(t alf)
)

)
(setvar "blipmode" 0) ;
(if (= s "0")
(progn

(setq p4(polar p0 a1 (* 0.933333 h)))

(command "line" p1 p0 p3 "")


(command "circle" p4 (* 0.466666 h))
)

(progn ;
(command "line" p2 p3 p0 p1 "")
(if (> (strlen s) 3) 3p4

(setq p4(polar p4 (+ a1 (* 0.5 pi)) (* 0.4 h)))


)
(command "text" "m" p4 h alf s) m

)
)
(setvar "cmdecho" v1)
(setvar "blipmode" v2)
(princ)
)

8-9a
bp0alf

AutoCAD

(defun c:bearing( / p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10


p11 p12 p13 p14 pc pm1 pm2 pm3 a b alf r a1 a2 b1)
(setq p0(getpoint "p0: "))
(setq a(getdist p0 "A: "))

(setq b(getdist p0 "B: "))


(setq alf(getangle p0 "alf: "))
(setq r(* 0.25 a) a1 (* 0.5 a) a2 (* 0.2835 a) b1 (* 0.5
b))
(setq pm1(polar p0 (+ alf(* -0.5 pi)) a1))

(setq p1(polar pm1 alf b1))


(setq p2(polar p1 (+ alf

pi) b))p1p8

(setq p3(polar p1 (+ alf(* 0.5 pi)) a2))

(setq p4(polar p2 (+ alf(* 0.5 pi)) a2))


(setq p7(polar p1 (+ alf(* 0.5 pi)) a))
(setq p8(polar p2 (+ alf(* 0.5 pi)) a))

(setq p5(polar p7 (+ alf(* -0.5 pi)) a2))


(setq p6(polar p8 (+ alf(* -0.5 pi)) a2))
(command "line" p1 p7 p8 p2 "c")
(command "circle" p0 r)
(command "line" p3 p4 "")

(command "line" p5 p6 "")


(setq pc(polar p0 alf r))
setq pm2(polar p4 alf b1))
(setq pm3(polar p6 alf b1))

(command "trim" pc "" pm2 pm3 "")

(setq p9(polar p0 (+ alf (* -0.5 pi)) (* 0.35 a)))


(setq p10(polar p0 (+ alf (* 0.5 pi)) (* 0.35 a)))
(command "bhatch" "p" "ansi31" "1" "0" p9 "")
(command "bhatch" "p" "ansi31" "1" "90" p10 "")
(command "linetype" "set" "center" "")
(setq p11(polar p0(+ alf(* -0.5 pi)) (+ a1 5)))
(setq p12(polar p0(+ alf(* 0.5 pi))(+ a1 5)))
(setq p13(polar p0 alf (+ b1 5)))

(setq p14(polar p0 (+ alf pi) (+ b1 5)))


(command "line" p11 p12 "");
(command "line" p13 p14 "")
(command "linetype" "set" "bylayer" "")
)

8.9

1.

1
6

7 4 3 50 68 62

1 1 2 2
827(a)6
1 7 2 4 3 3 1 50 2 68 3 62

L1 7 L2 4 L3 3 d1 50 d2 68 d3 62

3AutoLISP
AutoLISP
827(a)6
((1 7)(2 4)(3 3)(1 50)(2 68)(3
62))

2.
8-27
123123
XYalf

10-8.dat
d:\example\dat\

(("Name" " ")(" " "HT150")(" " 1)(" "


"1:1")("" "101"))
(("x" 120)("y" 160)("" 0))

(("1" 7)("2" 4)("3" 3))


(("1" 50)("2" 68)("3" 62))
3. AutoLIST
1
(open "" "")
nil""
"r","""w",
"""a",


(setq f1(open "d:\\example\\dat\\8-10.dat" "r"))
f1
2
(close )
(close f1)
3
(read-line)

(setq str1(read-line f1)

"(("" "")("" "HT150")(""


1)("" "1:1")("" "101"))"str1

4
(read )

(setq list1(read str1))


(("" "")("" "HT150")("" 1)(""
"1:1")("" "101"))list1

5
(cadr(assoc ))
(setq n(cadr(assoc "" list1)))

assoclist1("" 1)
cadr11n

4.

8-27(c)

8-108-17(a)
d\example\dat\8-10.dat
;8-10
(defun c:duangai(/ v1 v2 f1 list1 list2 list3 x0 y0 alf
l1 l2 l3 d1 d2 d3 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11
p12)
(setq v1(getvar "cmdecho"))
(setq v2(getvar "blipmode"))

(setvar "blipmode" 0)
(setvar "cmdecho" 0)

(setq f1(open "d:\\example\\dat\\8-101.dat" "r"));

(setq list1(read(read-line f1)));


(setq list2(read(read-line f1)));
(setq x0(cadr(assoc "x" list2)));X
x0
(setq y0(cadr(assoc "y" list2)))

(setq alf(cadr(assoc "" list2)))


(setq list3(read(read-line f1)));
(setq l1(cadr(assoc "1" list3)))
(setq l2(cadr(assoc "2" list3)))
(setq l3(cadr(assoc "3" list3)))

(setq list4(read(read-line f1)))

(setq d1(cadr(assoc "1" list4)))


(setq d2(cadr(assoc "2" list4)))

(setq d3(cadr(assoc "3" list4)))


(setq p0(list x0 y0))
;
(setq p1(polar p0 (+ alf (* 0.5 pi)) (* 0.5 d1)))
(setq p2(polar p0 (+ alf (* 0.5 pi)) (* 0.5 d2)))
(setq p3(polar p2 alf l3))
(setq p4(polar p3 (+ alf (* -0.5 pi)) (* 0.5 (- d2
d3))))
(setq p5(polar p4 alf (- l1 l3)))
(setq p6(polar p5 (+ alf (* -0.5 pi)) d3))

(setq p7(polar p4 (+ alf (* -0.5 pi)) d3))


(setq p8(polar p3 (+ alf (* -0.5 pi)) d2))

(setq p9(polar p2 (+ alf (* -0.5 pi)) d2))


(setq p10(polar p1 (+ alf (* -0.5 pi)) d1))
(setq p11(polar p10 alf l2))
(setq p12(polar p11 (+ alf (* 0.5 pi)) d1))
;

(command "layer" "m" "zhongxinxian" "l" "center" ""


"")
(command "line" (polar p0 (+ alf pi) 5) (polar p0 alf
(+ l1 5)) "")
;
(command "layer" "m" "cushixian" "lw" 0.3 "" "")

(command "line" p1 p10 "")


(command "pline" p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11
p12 "c")
(command "zoom" "e")
;

(command "layer" "m" "poumianxian" "")


(command "hatch" "ansi31" 1.0 0 "l" "")
;
(command "dimlinear" p9 p6 "hor" "@0,-10");l1
(command "dimlinear" p10 p11 "hor" "@0,10");l2

(command "dimlinear" p2 p3 "hor" "@0,3");l3


(command "dimlinear" p1 p10 "ver" "t" "%%c<>" "@10,0");d1

(command "dimlinear"
18,0");d2

p2

(command "dimlinear"
"@12,0");d3

p9
p5

"ver"
p6

"t"

"ver"

"%%c<>"
"t"

"@-

"%%c<>"

(close f1);

(setvar "cmdecho" v1);


(setvar "blipmode" v2);
(princ);
)
Command:duangai

8-10.dat

9.1
AutoCAD

16

entnext

entlast

entnext


(setq e1(entnext))
<Entity name: 7ef6ce88>e1

(setq e2(entnext e1))e1


<Entity name: 7ef6ce90>
e2
(setq e3(entnext e2))e2
<Entity name: 7ef6ce98>
e3
(setq e4(entlast))
<Entity name: 7ef6ce98>
e1
3e3
e4

9-14

1
e1
e2e3e4

(command "layer" "m" "zhongxin" "l" "center" "" "")


(command "line" "-5,0" "5,0" "")
(setq e1(entlast))
(command "line" "0,-5" "0,5" "")
(setq e2(entlast))

(command "layer" "m" "cuxian" "lw" 0.3 "" "")


(command "circle" "0,0" 3)
(setq e3(entlast))

(command "layer" "m" "xixian" "")


(command "arc" "-3.5,0" "0,3.5" "0,-3.5")

(setq e4(entlast))
AutoCADcopy3

(command "copy" e1 e2 e3 e4 "" "m" "0,0" "12,0"


"24,0" "36,0" "")

[9-2] bp0d
bh
AutoCAD

(defun c:keyway()
(setq pc (getpoint " "))
(setq d (getdist pc ""))
(setq b (getdist pc ""))

(setq w (getdist pc ""))


(setq r (* 0.5 d))
(command "circle" pc r)
(setq e1 (entlast)) entlaste1

(setq p0(polar pc 0 r)) p0


(setq p1(list (car pc) (+ (cadr pc) (* 0.5 b))))
(setq p2(list (+ (car pc) (* 1.2 r)) (cadr p1)))
(command "line" p1 p2 "")

(setq e2 (entlast)) entlaste2


(setq p3(list (car pc) (- (cadr pc) (* 0.5 b))))
(setq p4(list (car p2) (cadr p3)))
(command "line" p3 p4 "")

(setq e3 (entlast)) entlaste3


(setq p5(list (+ (car pc) (- r w)) (+ (cadr pc) (* 0.5
b))))
(setq p6(list (+ (car pc) (- r w)) (- (cadr pc) (* 0.5
b))))

(command "line" p5 p6 "")


(setq e4 (entlast)) entlaste4
e1e2p0p1

(command "trim" e1 e2 e3 e4 "" p0 p1 p2 p3 p4 "")

e1e2
(command "hatch" "ansi31" "2"
)

"0" e1 e2 e3 e4 "")

9.2

9.2.1
3
(command "text" "10,20" 5 0 "ABCDE")
(setq e(entlast))e
(setq elist(entget e)) e
"Command:"!elist"_$"
elist

((-1 . <Entity name: 7ef69500>)


(0 . "TEXT")
(330 . <Entity name: 7ef67d00>)

(5 . "19F")
(100 . "AcDbEntity")AutoCAD
(67 . 0)
(410 . "Model")

(8 . "0")
(100 . "AcDbText") AutoCAD
(10 10.0 20.0 0.0)
(40 . 5.0)

(1 . "ABCDE")

(50 . 0.0)

(41 . 1.0)
(51 . 0.0)
(7 . "STANDARD")
(71 . 0)
(72 . 0)

(11 0.0 0.0 0.0)


(210 0.0 0.0 1.0)
(100 . "AcDbText") AutoCAD
(73 . 0)
)

1
DXF
AutoCADDXF
2
2.4

9.2.2
elistAutoLISP

1
(cdr (assoc 0 elist))

0elist
(0 . "")
cdr2""
"LINE"
"TEXT"

2
(cdr (assoc 8 elist))
8elist
(8 . "")cdr
2""

3
(cdr (assoc 40 elist))
40elist
(40 . )
cdr2

4
(cdr (assoc 10 elist))

10elist

(10 )cdr
1XYZ
5

(setq elist (subst (cons 40 h)(assoc 40 elist)elist))


(cons 40 h)40 . 3.5(assoc 40
elist)elist40 . 5.0subst
40 . 3.5elist40 . 5.0
setqelist

6
(entmod elist)

entmod
5.03.5

9.2.3
9-3

e1

e1

e1nil

TEXTMTEXT

MTEXT

MTEXT

e1"TEXT"

e1

e1e1

(defun c:cth( / h e el)


(setq h(getdist "\n: "))

(setq e(entnext))
(while e e
(setq el(entget e))
(if (= "TEXT" (cdr (assoc 0 el)))
(progn "TEXT"

(setq el(subst (cons 40 h)(assoc 40 el)el))

(if (= 3 (cdr (assoc 72 el)))Align

(setq el(subst (cons 72 0) (assoc 72 el) el))

(entmod el)el
)
)
(setq e(entnext e))ee
)
(princ)
)

9.3

9.3.1
1(ssget [] [1 [2]] [] [])

CCrossing12

CPCpolygon

FFence

IImpliedGrips
LLast

nil
PPrevious
WWindow12

WPWpolygon

:E
:Nssnamex
"W""C"

:S
12

entget
(0 . "LINE") (8 . "LAYER1") (6 .

"center")(62 . 1)1
AutoCADDXF

"Select objects"

AutoLISP128

<Selection
set: 1>nil

(setq s1 (ssget '(2 2)))


(2,2)
s1

(setq s2 (ssget "w" '(0

0) '(10

10)))

(0,0)(10,10)

s2

(setq s3 (ssget "X" '((0 . "LINE") (62 . 5))))

((0 . "LINE") (62 . 5))


s3

(setq s4 (ssget))
"Select objects"

"Select objects"
s4

2(entsel [])

"Select object"

UCS

3(ssadd [ []])

4(ssdel )

5(sslength ss)

6(ssname )

9.3.2
9-4
(defun c:csth( / h s1 n e el)
(setq h(getdist "\n"))
(setq s1(ssget))

(setq n 0) 0
(repeat (sslength s1)
(setq e(ssname s1

n))n

(setq el(entget e))

(if (= "TEXT" (cdr (assoc 0 el)))TEXT


(progn TEXT

(setq el(subst (cons 40 h) (assoc 40 el) el))

(if (= 3 (cdr (assoc 72 el))) Align


(setq el(subst (cons 72 0)(assoc 72 el) el))

(entmod el) el
)
)
(setq n(1+ n)) n1

)
)

9.4
AutoCAD

9.4.1
1(tblnext [])
"LAYER" "LTYPE" "VIEW" "STYLE"
"BLOCK""UCS""APPID""DIMSTYLE""VPORT"
Tnil

"0"
"layer1" "layer2""layer3"

(tblnext "layer" T)((0 .


"LAYER") (2 . "0") (70 . 0) (62 . 7) (6 .
"CONTINUOUS"))T

(tblnext "layer"
nil)
(tblnext "layer") ((0 . "LAYER") (2 . "
layer1") (70 . 0) (62 . 7) (6 . "CONTINUOUS"))
nil
layer2layer3
nillayer3


"BOX"(tblnext "block")
((0 . "BLOCK") (2 . "BOX") (70 . 0) (10 9.0
2.0 0.0) (-2 . < 1dca370>))
2(tblobjname )

entgetentmod
(tblobjname "layer" "0")
0<Entity name: 4002cc80>

3(tblsearch [])
""
Ttblnext

(tblsearch "layer" "" t) ((0 . "LAYER") (2 .


"layer1") (70 . 0) (62 . 7) (6 . "CONTINUOUS"))
layer1(tblnext
"layer" )((0 . "LAYER") (2 . "layer2") (70 .

0) (62 . 7) (6 . "CONTINUOUS"))

(defun c:ccolor (/ oldcolor newcolor


old_cl layname laytab laycolor)

new_cl

el

(setq oldcolor (getint "\n: "))


(setq newcolor (getint "\n: "))
(setq new_cl (cons 62 newcolor)) ;

(setq e (entnext)) ;
(while e ;
(setq el (entget e)) ;
(if(= "LINE" (cdr (assoc 0 el)));

(progn ;
(setq old_cl (assoc 62 el)) ;
(if (null old_cl);

(progn ;
(setq layname (cdr (assoc 8 el))) ;
(setq laytab (tblsearch "LAYER" layname)) ;

(setq laycolor (cdr (assoc 62 laytab))) ;


(if(= oldcolor laycolor);
(progn ;
(setq el (cons new_cl el)) ;
(entmod el);el
)))

(progn ;
(if(= oldcolor (cdr old_cl));

(progn ;
(setq el (subst new_cl old_cl el)) ;
(entmod el) ; el
))))))
(setq e (entnext e));ee
))

10
AutoLISPActiveX

ActiveX Automation
AutoCADAutoCAD
ActiveXAutoLISP
ActiveX
ActiveXC++Visual
BasicJavaDelphiAutoLISPActiveX
ActiveX

AutoLISPActiveXvlload-comActiveXvl-load-com
ActiveX
ActiveXVisual LISP
vl-load-com

10.1 AutoCAD
ActiveX
ActiveX
AutoCAD
(linetype)(style)
(dimstyle)
(layer)(block)
(view)(viewport)

(modelspace)(paperspace)
AutoCAD

AutoCAD
AutoCADAutoCAD
10-1

10-1 AutoCAD

AutoCAD

AutoCAD
Mirror
MoveOffset

AutoCAD
AutoCAD

10.2.1AutoCAD
1. AutoCAD
AutoCADAutoCADAutoCAD
AutoCADAutoCAD
vlax-get-acad-object

(setq myacad(vlax-get-acad-object))
AutoCAD
#<VLA-OBJECT IAcadApplication 00b5e51c>
VLAVLISP ActiveX

AutoCADmyacad

2. AutoCAD
vlax-dump-object VLA [T],
VLAVLAT
VLA

(vlax-dump-object myacad t)
; IAcadApplication: An instance of the AutoCAD application
; Property values:
; ActiveDocument = #<VLA-OBJECT IAcadDocument 01165340>
; Application (RO) = #<VLA-OBJECT IAcadApplication 00b5e51c>
; Caption (RO) = "AutoCAD 2006 [Drawing1.dwg]"
; Documents (RO) = #<VLA-OBJECT IAcadDocuments 011b9ba0>
; FullName (RO) = "C:\\Program Files\\AutoCAD 2006\\acad.exe"

; Height = 730
; HWND (RO) = 66224

; LocaleId (RO) = 1033


; MenuBar (RO) = #<VLA-OBJECT IAcadMenuBar 011bdf94>
; MenuGroups (RO) = #<VLA-OBJECT IAcadMenuGroups 003d3aa0>
; Name (RO) = "AutoCAD"
; Path (RO) = "C:\\Program Files\\AutoCAD 2006"

; Preferences (RO) = #<VLA-OBJECT IAcadPreferences 011bdf6c>


; StatusId (RO) = ...Indexed contents not shown...
; VBE (RO) = AutoCAD: Problem in loading VBA

; Version (RO) = "16.2s (LMS Tech)"


; Visible = -1
; Width = 1020
; WindowLeft = 2
; WindowState = 1

; WindowTop = 2

; Methods supported:

; ZoomCenter (2)

; Eval (1)

; ZoomExtents ()

; GetAcadState ()
; GetInterfaceObject (1)

; ListArx ()
; LoadArx (1)
; LoadDVB (1)
; Quit ()
; RunMacro (1)

; UnloadArx (1)
; UnloadDVB (1)
; Update ()
; ZoomAll ()

; ZoomPickWindow ()
; ZoomPrevious ()
; ZoomScaled (2)
; ZoomWindow (2)

Property valuesAutoCAD
ActiveDocumentApplication
CaptionFullName
#<VLA-OBJECT >VLA
ActiveDocumentDocuments
MenuBar ()MenuGroups ()Preferences ()
VLA
ActiveX

(RO)
Caption (RO) = "AutoCAD 2006 [Drawing1.dwg]"
AutoCAD"AutoCAD 2006 [Drawing1.dwg]"

Methods supported ()
AutoCADEvalGetAcadStateGetInterface
Object

10.2.2AutoCAD
AutoCADAutoCAD
VLA
AutoCADvla-get-

vla-get-property object
objectVLApropertyobjectVLA
vlax-dump-object
(10,20)(60,20)
(35,20)25
AutoCADAutoCAD

1. AutoCAD
(setq myacad (vlax-get-acad-object))
;AutoCAD#<VLA-OBJECT IAcadApplication 00b5e51c>
myacad

2. AutoCAD
(vlax-dump-object myacad);
:;ActiveDocument=#<VLA-OBJECT IAcadDocument 01165340>
ActiveDocumentAutoCADAutoCAD
VLA

3.
(setq mydoc(vla-get-ActiveDocument myacad));
#<VLA-OBJECT IAcadDocument 01165340>
mydoc

4.
(vlax-dump-object mydoc)

;ModelSpace (RO) = #<VLA-OBJECT IAcadModelSpace 011c1e04>


ModelSpaceVLA
5.
(setq myms(vla-get-ModelSpace mydoc))
#<VLA-OBJECT IAcadModelSpace 011c1e04>
myms
6.
(vlax-dump-object myms t)

; Count (RO) = 2
Add3Dface Add3Dmesh Add3Dpoly AddArc
AddAttribute AddBoxAddCircleItem
Item0

7.
(setq myline(vla-item myms 0))
, #<VLA-OBJECT
IAcadLine 011b9e74>myline
8.

(vlax-dump-object myline t)

; Property values:
; Angle (RO) = 0.0
; Application (RO) = #<VLA-OBJECT IAcadApplication 00b5e51c>

; Delta (RO) = (50.0 0.0 0.0)


; Document (RO) = #<VLA-OBJECT IAcadDocument 01165340>
; EndPoint = (60.0 20.0 0.0)

;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;

Handle (RO) = "81"


HasExtensionDictionary (RO) = 0
Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 040a53f4>
Layer = "0"
Length (RO) = 50.0
Linetype = "ByLayer"
LinetypeScale = 1.0
Lineweight = -1
Normal = (0.0 0.0 1.0)
ObjectID (RO) = 2129985160
ObjectName (RO) = "AcDbLine"
OwnerID (RO) = 2129984760
PlotStyleName = "ByLayer"
StartPoint = (10.0 20.0 0.0)
Thickness = 0.0
TrueColor = #<VLA-OBJECT IAcadAcCmColor 040a6db0>
Visible = -1


X0(50.0 0.0 0.0)
(60.0 20.0 0.0)"81"
"0"50.0"ByLayer"1.0
-1 (0.0 0.0 1.0)
"ByLayer"(10.0 20.0 0.0) 0.0

; Methods supported:
; ArrayPolar (3)
; ArrayRectangular (6)

; Copy ()
; Delete ()
; GetBoundingBox (2)
; GetExtensionDictionary ()

; GetXData (3)
; Highlight (1)
; IntersectWith (2)
; Mirror (2)

; Mirror3D (3)
; Move (2)
; Offset (1)
; Rotate (2)
; Rotate3D (3)

; ScaleEntity (2)
; SetXData (2)
; TransformBy (1)
; Update ()


ArrayPolarArrayRectangular
CopyDelete GetBoundingBox
( ) GetExtensionDictionary ( )
GetXData ( ) Highlight ( )
IntersectWith()Mirror()Mirror3D()
Move()Offset()Rotate()Rotate3D(
) ScaleEntity( ) SetXData( )
TransformBy()Update()

9.
(setq mycircle(vla-item myms 1))

,#<VLA-OBJECT IAcadCircle
011bed74>myline
10.
(vlax-dump-object mycircle t)

Area= 1963.5 Center= (35.0 20.0


0.0)Circumference= 157.08Diameter=
50.0Radius= 25.0

10.2.3 AutoCAD
AutoCAD
AutoCAD
AutoCAD

1.AutoCAD
(setq myacad (vlax-get-acad-object))

AutoCAD #<VLA-OBJECT
IAcadApplication 00b5e51c>myacad

2.AutoCAD

VLA
myacad10-2 AutoCAD

10-2 AutoCAD

3.
AutoCADActive
Document10-3

10-3

4.
ModelSpace104Count
2

10-4

5.
VLA
VLA
(setq myacad (vlax-get-acad-object))
(setq mydoc(vla-get-ActiveDocument myacad))
(setq myms(vla-get-ModelSpace mydoc))
(setq myline(vla-item myms 0))
VLA
mylinemyline
5

10-

10-5

6.
VLA

(setq mycircle(vla-item myms 1))

mycirclemycircle

10-6

VLA10.2.1
vlax-dump-object
VLA

10-6

10.2.4HelpAutoCAD
HelpAutoCAD
VLISPF1
AutoCAD 2006 Help:Developer Documentation

ObjectsAutoCAD
107

107

Addline

AutoCAD
VLA10.2
vlax-dump-objectVLA

10.3 Visual LISPActiveX


10.3.1HelpAutoCAD

10.2vlax-dump-object
AutoCAD
Addline
AutoCAD
107
Addline108

108

Visual LISP
Visual BasicVisual BasicAddLine

RetVal = object. AddLine(StarPoint,EndPoint)


object
StarPointEndPointVariant3

Visual LISP

1Visual BasicAutoLISP
2AutoLISPActiveX

10.3.2 Visual BasicAutoLISP


Visual Basic
RetVal = object.AddLine(StartPoint,EndPoint)
RetValobjectAddLineStartPoint
EndPointAddLine
VLISP ActiveX
AddLineStartPoint
EndPointAddLine myline
valx-3d-pointVLISP ActiveX
AutoLISP3ActiveX

AutoLISP
(setq myline(vla-addline myms (vlax-3d-point '(10 20)) (vlax-3dpoint '(80 30))))
myms

(setq myacad (vlax-get-acad-object))


(setq mydoc(vla-get-ActiveDocument myacad))
(setq myms(vla-get-ModelSpace mydoc))
vlax-3d-pointVLISP ActiveXAutoLISP23
ActiveX
10-9
RetVal

object .

AddLine

(StartPoint,

EndPoint)

(setq myline(vla-addline myms (vlax-3d-point '(10 20)) (vlax-3d-point '(80 30))))

10-9 Visual BasicAutoLISP

10.3.3 ActiveXAutoLISP
AutoLISPActiveXActiveX
10-1ActiveXAuto
LISP1ActiveX1
AutoLISP(+)ActiveX
AutoLISP
10-1 AutoLISPActiveX

VLA

:vlax_true:vlax_false
+

+
+
+
+

+
+
+
+
+

10.3.4 VLISP
ActiveXVLISP
AutoLISP
1. variant
ActiveX
ActiveXAutoLISP

10-1
ActiveX

ActiveX

1
vlax-make-variant
(vlax-make-variant [] [])
vlax-vbEmpty
10-2
2
vlax-vbInteger
AutoCAD

LISP
ActiveX10-3

10-2

Vlax-vbEmpty

Vlax-vbNull

Vlax-vbInteger

Vlax-vbLong

Vlax-vbSingle

Vlax-vbDouble

Vlax-vbString

Vlax-vbObject

Vlax-vbBoolean

11

Vlax-vbArray

8192

10-3 LISPActiveX
LISP

Nil

vlax-vbEmpty

vlax-null

vlax-vbNull

Integer

vlax-vbLong

Real

vlax-vbDouble

String

vlax-vbString

VLA-object

vlax-vbObject

vlax-truevlax-false

vlax-vbBoolean

Variant

vlax-make-safearray

vlax-vbArray


(setq varnil(vlax-make-variant));#<variant 0>
0vlax-vbEmptynil

(setq varint (vlax-make-variant 50 vlax-vbInteger));


#<variant 2 50> 2 vlaxvbInteger50

(setq varlng(vlax-make-variant 5));#<variant 3 5>


3vlax-vbLong5

(setq

varstr(vlax-make-variant

"tsinghua"));

#<variant 8 tsinghua>8
vlax-vbString"tsinghua"

2
vlax-variant-type
10-2
(vlax-variant-type varnil)
(vlax-variant-type varnil) nil
(vlax-variant-type varint) 2vlax-vbInteger
(vlax-variant-type varstr) 8vlax-vbString

3
vlax-variant-value
(vlax-variant-value )
(vlax-variant-value varnil) nil
(vlax-variant-value varint) 50
(vlax-variant-value varstr) "tsinghua"

4
vlax-variant-change-type
10-2var
nil

(vlax-variant-change-type )
varint
(setq varint (vlax-make-variant 5)) ;#<variant 3 5>
varintstr varint

(setq varintStr (vlax-variant-change-type varint vlax-vbstring)) ;


#<variant 8 5>

varintstr

_$ (vlax-variant-value varintStr) ;"5"


varintstr

2.
VLISP
AutoLISP
ActiveXVLISP

1
vlax-make-safearray
(vlax-make-safearray '( . ) [ '( . )...])

10-4

10-4

vlax-vbInteger

Vlax-vbLong

Vlax-vbSingle

Vlax-vbDouble

Vlax-vbString

Vlax-vbObject

Vlax-vbBoolean

11

Vlax-vbVariant

12

AutoCAD

'( . ) [ '( . )...]

016

(setq p1 (vlax-make-safearray vlax-vbDouble '(0 . 2)))


#<safearray...>p10
2
(setq mt2(vlax-make-safearray vlax-vbString '(0 . 1) '(1 . 3)))
#<safearray...>mt2
0113

10-5
10-5

vlax-false

nil
(vlax-vbEmpty)

vlax-safearray-fill

(vlax-safearray-fill

')

#<safearray...>
p10
2vlax-safearray-fill

(vlax-safearray-fill p1 '(1 2 3));#<safearray...>


vlax-safearray-fill
(vlax-safearray-fill p1 '(1 2 3 4)) error: vlaxsafearray-fill failed. Invalid initialization list.

mt2
01
13vlax-safearray-fill

(vlax-safearray-fill mt2 '(("a" "b" "c") ("d" "e"


"f"))) ;#<safearray...>

3
vlax-safearray->list
(vlax-safearray->list )

(vlax-safearray->list p1) ;(1.0 2.0 3.0)


(vlax-safearray->list mt2) ;(("a" "b" "c") ("d" "e" "f"))

4
vlax-safearray-put-element

(vlax-safearray-put-element ...)
SafeArray

p10
2vlax-safearray-put-element

(vlax-safearray-put-element p1 0 10)10p11
10(vlax-safearray-put-element p1 1 20)20p1
220(vlax-safearray-put-element p1 2 30)30
p1330 vlax-safearray->list p1
(10.0 20.0 30.0)
mt201
13

12vlax-safearray-put-element
(vlax-safearray-put-element mt2 0 1 "a1")"a1"
(vlax-safearray-put-element mt2 0 2 "b2")"b2"
(vlax-safearray-put-element mt2 0 3 "c3")"c3"
(vlax-safearray-put-element mt2 1 1 "d4")"d4"

(vlax-safearray-put-element mt2 1 2 "e5")"e5"


(vlax-safearray-put-element mt2 1 3 "f6")"f6"
vlax-safearray->list mt2

(vlax-safearray->list mt2)(("a1" "b2" "c3") ("d4" "e5" "f6"))

5
ActiveX

5

(setq a5(vlax-make-safearray vlax-vbDouble '(0 . 4)))

(vlax-safearray-fill a5 '(1.1 2.2 3.3 4.4 5.5))

(setq

vara5

(vlax-make-variant

a5)) #<variant

8197 ...>

vara55

6vlax-3d-pointActiveX
vlax-3d-point3
(vlax-3d-point 32)
ActiveXCircleCenter
(setq CircleCenter (vlax-3d-point '(12.5 10 0))) #<variant
8197 ...>

(setq CircleCenter (vlax-3d-point '(12.5 10 ))) #<variant


8197 ...>

(setq CircleCenter (vlax-3d-point 12.5 10 0)) #<variant


8197 ...>

(setq

CircleCenter

(vlax-3d-point

12.5

10)) #<variant

8197 ...>

vlax-3d-point

Z vlax-3d-point
0
vlax-safearray->listvlax-3d-point
(vlax-safearray->list (vlax-variant-value circcenter))(12.5 10.0 0.0)

10.3.5 AutoCADVLA
1. AutoCADVLA

vlax-ename->vla-objectAutoCAD
VLA
(vlax-ename->vla-object AutoCAD)
VLA

(setq e1(entnext)) <Entity name: 7ef4fe88>


vlax-ename->vla-objectVLA
(setq vla-object(vlax-ename->vla-object e1))
#<VLA-OBJECT IAcadCircle 03743414>

2. VLAAutoCAD
vlax-vla-object->ename VLA
AutoCAD
(vlax-vla-object->ename VLA)
AutoCAD

vla-objectVLA
VLAAutoCAD

(setq new-ename(vlax-vla-object->ename vla-object))


<Entity name: 7ef4fe88>

2. VLAAutoCAD
vlax-vla-object->ename VLA
AutoCAD
(vlax-vla-object->ename VLA)
AutoCAD
vla-objectVLA
VLAAutoCAD
(setq new-ename(vlax-vla-object->ename vla-object))
<Entity name: 7ef4fe88>

(100 80)50
VLAcirc

1. vla-get
(vla-get-property VLA)
vla-get-propertyproperty
VLA

(setq rad(vla-get-radius circ))50.0

(setq area(vla-get-area

circ))7853.98

(setq area(vla-get-color

circ))256(bylayer)

(setq cntr(vla-get-center circ))#<variant 8197 ...>


vlax-safearray->list

(vlax-safearray->list (vlax-variant-value cntr)) (100.0 80.0


0.0)

2. vlax-get-propertyActiveX
vlax-get-property
(vlax-get-property VLA property)
property

(setq rad(vlax-get-property circ 'radius))50.0

(setq area(vlax-get-property circ 'area))7853.98

(setq

cntr

(vlax-get-property

circ

8197 ...>,

(vlax-get-property circ 'Color)256

'center)) #<variant

10.4.2
(100 80)50
VLAcirc

1. vla-put-
(vla-put-property VLA )
vla-put- property
propertyVLA
property
radius20

(vla-put-radius circ 20)nil,


20


(vla-put-area
1000

circ 1000)nil,

(vla-put-center circ (vlax-3d-point '(150 50 0)))


nil, (150 50 0)

vlax-3d-point
ActiveX
AutoCAD
AutoCAD

vla-update
(vla-update VLA)

2.vlax-put-propertyActiveX

vlax-put-property
(vlax-put-property VLA property )
property

(vlax-put-property circ 'radius 80) nil,


20

(vlax-put-property circ 'area 2004) nil,


2004


(vlax-put-property circ 'center (vlax-3d-point '(180
20 0))); nil, (180 20 0)

(vlax-put-property circ 'Color acRed)


(vlax-put-property circ 'Color 1)

acRed1

(vla-put-color myCircle acRed)

10.5
AutoCAD

10.7AutoCAD

VLISP

l vlax-read-enabled-p
l vlax-write-enabled-p

l vlax-erased-p

Tnil

myline

(1)
(vlax-read-enabled-p myline) T
(2)
(vlax-write-enabled-p myline) T
(3)
(vlax-erased-p myline) nil
(vla-delete myline) myline,nil

(4) vlax-read-enabled-pmyline
(vlax-read-enabled-p myline) nil
(5) vlax-erased-p
(vlax-erased-p myline) T

10.6 ActiveX
ActiveX
GetBoundingBox 10-10 ActiveX and VBA
Reference

10-10
GetBoundingBox

10-10GetBoundingBox
MinPointMaxPoint
WCS
20010050

GetBoundingBox
MinPointMaxPoint
1
(setq ec(entlast)) <Entity name: 7ef67e98>
2VLA
(setq mycircle(vlax-ename->vla-object ec)) #<VLAOBJECT IAcadLine 011bf2d4>

3 GetBoundingBox
MinPointMaxPoint
(vla-getboundingbox myCircle 'minpoint 'maxpoint)
nil

vla-getboundingbox
minpointmaxpoint

4vlax-safearray->listminpointmaxpoint

(setq p1(vlax-safearray->list

minpoint)) (150.0 3.0

0.0)

(setq p2(vlax-safearray->list
0.0)

maxpoint))(190.0 20.0

10.7

vlax-method-applicable-p vlax-property-available-p

Tnil
1. 12
vlax-method-applicable-p

(vlax-method-applicable-p VLA method)

method
VLATnil

copymyline

(vlax-method-applicable-p myline "copy");Tcopy

AddBoxmyline

(vlax-method-applicable-p myline "AddBox") nil


AddBox

2.
vlax-property-available-p

(vlax-property-available-p VLA
modify)

property [check-

propertycheckmodifyTVLAVLA
TnilcheckmodifyTnil
ColorCentermyline
(vlax-property-available-p myline "Color")T

(vlax-property-available-p myline "Center")nil


myCircleVLA
"T"Area

(vlax-property-available-p myCircle "area") Tarea

TArea

(vlax-property-available-p myCircle "area" T) Tarea

10.8

AutoCADAutoCAD

AutoCADVLISP
vlax-map-collectionvlax-for
10.8.1 14
vlax-map-collection

(vlax-map-collection collection-object function)


collection-objectVLAfunction
collection-objectlambda
VLA

(vl-load-com)
(setq myacad (vlax-get-acad-object))
(setq mydoc(vla-get-ActiveDocument myacad))
(setq myms(vla-get-ModelSpace mydoc))
(vlax-map-collection myms 'vlax-dump-Object)

; IAcadCircle: AutoCAD Circle Interface


; Property values:
; Application (RO) = #<VLA-OBJECT IAcadApplication
00b5e51c>

; Area = 7853.98

; Center = (200.0 100.0 0.0)


; Circumference = 314.159

; Diameter = 100.0
; Document(RO)=#<VLA-OBJECT IAcadDocument 011ce690>
; Handle (RO) = "84"
; HasExtensionDictionary (RO) = 0
;
Hyperlinks
011c00c4>

(RO)=#<VLA-OBJECT

; Layer = "0"
; Linetype = "ByLayer"
; LinetypeScale = 1.0

IAcadHyperlinks

; Lineweight = -1
; Normal = (0.0 0.0 1.0)
; ObjectID (RO) = 2130083424
; ObjectName (RO) = "AcDbCircle"
; OwnerID (RO) = 2130083064

; PlotStyleName = "ByLayer"
; Radius = 50.0

; Thickness = 0.0
; TrueColor = #<VLA-OBJECT IAcadAcCmColor 011c0050>
; Visible = -1

10.8.2

vlax-for

(vlax-for
symbol
[expression2 ...]])

collection

[expression1

symbolVLA
collectionVLAexpression1,
expression2... foreach
for

10-1vlax-forvlax-for

10-1
(defun
show-Color-Statistics
colorList)

(/

objectColor

(setq modelSpace (vla-get-ModelSpace


(vlax-get-Acad-Object))))

colorSublist

(vla-get-ActiveDocument

(vlax-for obj modelSpace


(setq objectColor (vla-get-Color obj))
(if (setq colorSublist (assoc objectColor colorList))
(setq colorList
(subst
(cons
colorSublist colorList))

objectColor

(1+(cdr

colorSublist)))

(setq colorList (cons (cons objectColor 1) colorList)))


)

(if colorList

(progn
(setq colorList (vl-sort colorList '(lambda
(car lst1) (car lst2)))))
(princ "\nColorList = ")
(princ colorList)
(foreach subList colorList
(princ "\nColor ")

(princ (car subList))


(princ " is found in ")
(princ (setq count (cdr subList)))

(princ " object")


(princ (if (= count 1)
".

"s.")))))
(princ)
)

(lst1 lst2) (<

124
6
(show-Color-Statistics)

ColorList = ((1 . 2) (2 . 4) (256 . 6))


Color 1 is found in 2 objects.

Color 2 is found in 4 objects.


Color 256 is found in 6 objects.

10.8.3
itemcount
itemcount

1.
vla-get-count

(vla-get-count myms)
vla-item

(vla-item myms index)index


0VLA

2.

(setq index 0)index0


(repeat

(vla-get-count myms)

(setq ent-obj (vla-item myms index))VLA

(if (= "AcDbArc" (vla-get-objectname ent-obj))

(progn AcDbArc
(princ "\n")
(princ (vla-get-startangle ent-obj))
)
)
(setq index (+ index 1)) index1
)
itemcount

10.9 VLA
AutoCADVLA
VLAAutoCAD

equalVLAVLA
equal T
VLAvlax-release-objectVLA

(vlax-release-object VLA)
VLAVLA
vlax-release-object
AutoCAD
vlax-object-released-p
(vlax-object-released-p VLA)

VLATnil

10.10 ActiveX
ActiveX
ActiveX

vl-catch-all-applyActiveX

(vl-catch-all-apply 'function list)


functionlist
ActiveX
vl-catch-all-applyActiveX

1
210-2box1

10-2
(defun box1(/ mydoc myhndl myobj llpoint urpoint)
(vl-load-com)
(setq mydoc(vla-get-activedocument (vlax-get-acad-object)))
(setq myhndl(cdr (assoc 5(entget (car (entsel "\n
"))))))
(setq myobj(vla-handletoobject mydoc myhndl))
(vla-getboundingbox myobj 'llpoint 'urpoint)
(princ "\n")
(princ (vlax-safearray->list llpoint))
(princ " ")

(princ (vlax-safearray->list urpoint))


(princ)
)

Command:$

; error:
Automation Error. Invalid extentsAutomation

GetBoundingBox
Automation

310-3box2box2vlcatch-all-applyvla-getboundingbox
errerrActiveX
ActiveX

vl-catch-all-error-pvl-catch-allapplyvl-catch-all-apply
vl-catch-all-error-pTnil

10-3

(defun box2(/ mydoc myhndl myobj llpoint urpoint)


(vl-load-com)
(setq mydoc(vla-get-activedocument
object)))

(vlax-get-acad-

(setq myhndl(cdr (assoc 5(entget (car (entsel "\n


"))))))
(setq myobj(vla-handletoobject mydoc myhndl))
(setq
err(vl-catch-all-apply
(list myobj 'llpoint 'urpoint)))

'vla-getboundingbox

(if (vl-catch-all-error-p err)


(princ "\n !")

(progn

(princ "\n")
(princ (vlax-safearray->list llpoint))(princ " ")
(princ (vlax-safearray->list urpoint))))
(princ)
)

10.11
1. ActiveX
ActiveX AutoCAD
AutoLISP
ActiveX
10-4ActiveX
(defun c:actvline(/ myacad mydoc myms p1 p2 myline)
(vl-load-com)
(setq myacad (vlax-get-acad-object));AutoCAD
(setq mydoc(vla-get-ActiveDocument myacad));

(setq myms(vla-get-ModelSpace mydoc));


(setq p1(getpoint "\n:"))
(setq p2(getpoint p1 "\n:"))
;ActiveX

(setq myline(vla-addline myms (vlax-3d-point p1) (vlax-3d-point


p2)))
(princ)
)

2. ActiveX
ActiveX
VLA
10-5ActiveX

(defun c:chcircarea(/ ec area v_c)


(vl-load-com)
(setq ec(car (entsel "\n:")));
(setq area(getreal "\n:"));

(while (<= area 0)

(alert "0")
(setq area(getreal "\n:"));
)
(setq v_c(vlax-ename->vla-object ec));
VLA

(vla-put-area v_c area);


(princ)
)

11

11.1

1.
AutoCAD

lAutoCAD
DXF

l ARX

lAutoCAD

vlr-types11-1
AutoCAD

11-1AutoCAD

:VLR-AcDb-Reactor

:VLR- DocManager- Reactor

:VLR-Editor- Reactor

:VLR-Linker- Reactor

:VLR-Object- Reactor

11-211-1
11-2 :VLR-EditorReactor

11-2

:VLR-Command-Reactor

:VLR-DeepClone-Reactor
deep clone
:VLR-DWG-Reactor

:VLR-DXF-Reactor
DXF
:VLR-Insert-Reactor

:VLR-Lisp-Reactor
LISP
:VLR-Miscellaneous-Reactor
:VLR-Mouse-Reactor

:VLR-SysVar-Reactor

:VLR-Toolbar-Reactor

:VLR-Undo-Reactor
undo
:VLR-Wblock-Reactor

:VLR-Window-Reactor
AutoCAD
:VLR-XREF-Reactor
XREF

3.
AutoCAD

SaveAutoCAD
:vlr-beginSave
AutoCAD:vlr-saveComplete

vlr-reaction-names

(vlr-reaction-names

reactor-type)

reactor-type11-111-2


(vlr-reaction-names :VLR-DWG-Reactor)
(:VLR-beginDwgOpen

:VLR-endDwgOpen

:VLR-dwgFileOpened :VLR-

databaseConstructed :VLR-databaseToBeDestroyed :VLRbeginSave :VLR-saveComplete :VLR-beginClose)

(vlr-reaction-names :vlr-object-reactor)
;(:VLR-cancelled :VLR-copied :VLR-erased :VLR-unerased :VLRgoodbye :VLR-openedForModify :VLR-modified :VLR-

subObjModified :VLR-modifyUndone :VLR-modifiedXData :VLRunappended :VLR-reappended :VLR-objectClosed)

(defun print-reactors-and-events ()

(foreach rtype (vlr-types)


(princ (strcat "\n" (vl-princ-to-string rtype)))
(foreach rname (vlr-reaction-names rtype)
(princ (strcat "\n\t" (vl-princ-to-string rname)))))
(princ)

)
AutoLISP Reference

ActiveXvl-load-com
AutoLISP

11.2

AutoLISP
commandAutoCAD

ActiveX entgetentmod

11.2.1

(defun function
parameter-list))

(notifier-object

reactor-object

notifier-object
reactor-objec
parameter-list
11-1 print-radius
notifier-objectreactor-object
parameter-list
parameter-list

11-1print-radius

(defun print-radius (notifier-object reactor-object parameter-list)

(vl-load-com)
(cond
((vlax-property-available-p notifier-object "Radius")
radius

(princ ")

(princ (vla-get-radius notifier-object))


)
)
)

11.2.2
AutoCAD

(defun function(reactor-object parameter-list))

reactor-object
parameter-list

11-2saveDrawingInfocallingreactorcommandInfo

AutoCAD

11-2saveDrawingInfo
(defun

saveDrawingInfo(calling-reactor

commandInfo

dwgname

filesize)
(vl-load-com)
(setq

dwgname

(cadr

commandInfo)

filesize

(vl-file-size

dwgname))
(alert(strcat "" dwgname "" (itoa filesize)
"."))

(princ)
)

vl-file-size

11.2.3. AutoCAD
AutoCAD

1vlr-beep-reaction
vlr-beep-reaction
2vlr-trace-reaction
vlr-trace-reaction

VLISP

11.3

vlr--reactor
AutoLISP
vlracdb-reactorvlr-toolbar-reactor

AutoLISP Reference

vlr-DWG-reactor11-3
DWG

11-3 DWG

:vlr-beginClose

:vlr-databaseConstructed

:vlr-databaseToBeDestroyed

:vlr-beginDwgOpen

AutoCAD

:vlr-endDwgOpen

AutoCAD

:vlr-dwgFileOpened

AutoCAD

:vlr-beginSave

AutoCAD

:vlr-saveComplete

AutoCAD

11.3.1
AutoCAD

vlr-object-reactor
(vlr-object-reactor owners data callbacks)
ownersVLAVLA

datanil
callbacks

(event-name . callback_function)
event-name 11-4 Object
callback_function11-511-4

reactor_object

11-4 Object

:vlr-cancelled
:vlr-copied
:vlr-erased
:vlr-unerased
:vlr-goodbye
:vlr-openedForModify
:vlr-modified

:vlr-cancelled :vlr-modifyUndone
:vlr-subObjModified

:vlr-modifyUndone

:vlr-modifiedXData

:vlr-unappended

:vlr-reappended

:vlr-objectClosed

11-5 Object

:vlr-cancelled

:vlr-erased
:vlr-unerased
:vlr-goodbye
:vlr-openedForModify
:vlr-modified
:vlr-modifyUndone
:vlr-modifiedXData

:vlr-unappended
:vlr-reappended
:vlr-objectClosed

:vlr-copied

(ename)

:vlr-subObjModified

(ename)


VLAmyCircle

"Circle Reactor"(:vlr-modified .
print-radius) myCircle :vlrmodifiedprint-radius
(setq circleReactor (vlr-object-reactor (list myCircle)
"Circle Reactor" '((:vlr-modified . print-radius))))
circleReactor

1VLA
enameVLAActiveX
AutoCADActiveXVLA
entlastentget
VLAvlax-ename->vla-objectename
VLA

AutoCAD
:

111-3
11-3VLA
(setq myCircle

(progn
(setq ctrPt (getpoint "\n: ")
radius (distance ctrPt

(getpoint ctrpt "\n : "))

)
(vla-addCircle
(vla-get-ModelSpace

(vla-get-ActiveDocument (vlax-get-acad-object)))
(vlax-3d-point ctrPt)
radius
)))
vla-addCirclemyCircle
VLA

211-1 print-radius
3
(setq circleReactor (vlr-object-reactor (list myCircle)
"Circle Reactor" '((:vlr-modified . print-radius))))

4AutoCADprint-radius
AutoCADSTRETCH

** STRETCH **
Specify stretch point or [Base point/Copy/Undo/eXit]:
:190.0

STRETCH
:circleReactor

11.3.2
AutoCAD
vlr--reactor

(vlr--reactor data callbacks)


datanil
callbacks

(event-name . callback_function)
DWGSave
saveDrawingInfo
(vlr-dwg-Reactor

nil

'((:vlr-saveComplete . saveDrawingInfo)))

nil
:vlr-saveCompletesaveDrawingInfo
:vlr-saveCompleteAutoCAD


:vlr-saveComplete
AutoCADAutoLISP
DWG
saveDrawingInfo
Save
DWG
1) 11-2saveDrawingInfo
(2 DWG
(vlr-dwg-Reactor

nil

'((:vlr-saveComplete . saveDrawingInfo)))

3AutoCAD
11-1AutoCAD Message

11-1AutoCADMessage

11.3.3
data
nil

datanil

circleReactor
CircleReactorcircleReactor

11.4
11.4.1
VLISP
AutoLISP

1.
vlr-reactors
vlr-reactors

(vlr-reactors [reactor-type...])
reactor-type
reactor-type
reactor-type

(vlr-reactors) ((:VLR-Object-Reactor #<VLR-ObjectReactor>) (:VLR-Editor-Reactor #<VLR-Editor-Reactor>))


(vlr-reactors :vlr-object-reactor) ((:VLR-ObjectReactor #<VLR-Object-Reactor>))

(vlr-reactors :vlr-acdb-reactor) nil

DWG
(vlr-reactors :vlr-dwg-reactor) ((:VLR-DWG-Reactor
#<VLR-DWG-Reactor> #<VLR-DWG-Reactor>))DWG
DWG

2. VLISP
VLISPVLISP
circleReactor
11-2

11-2
l VLR-Object-Reactor
l <VLR-OBJECT IAcadCircle 03708534>

l : VLR-modified PRINT-RADIUS
l added-p T nil
l Circle Reactor

l active-document-only
l <VLA-OBJECT IacadDocument 01165340>
{Owners}

3.
VLISP

1vlr-type
(vlr-type circleReactor) :VLR-Object-Reactor
2vlr-current-reaction-name

(vlr-current-reaction-name) nil
3vlr-data

(vlr-data circleReactor) "Circle Reactor


4vlr-ownersAutoCAD
circleReactor

(vlr-owners circleReactor) (#<VLA-OBJECT IAcadCircle 03ad077c>)


5vlr-reactions
circleReactor

(vlr-reactions circleReactor) ((:VLR-modified . PRINT-RADIUS))

11.4.2
1
vlr-reaction-set

(vlr-reaction-set reactor event function)

reactor event
FunctionAutoLISP

circleReactor
print-area

(vlr-reaction-set circleReactor :vlr-modified 'printarea) PRINT-AREA

2.
vlr-data-set

(vlr-data-set obj data)


objdata
data
circleReactor
(vlr-data circleReactor) "Circle Reactor"
"Circle Area Reactor"circleReactor
"Circle Reactor"
(vlr-data-set circleReactor "Circle Area Reactor") ;"Circle
Area Reactor"

(vlr-data circleReactor) ;"Circle Area Reactor"


vlr-data-set

3.
vlr-owner-add

(vlr-owner-add reactor owner)


reactorowner
VLAVLA
archie
circleReactor
(vlr-owner-add circleReactor archie) #<vlaOBJECT IAcadArc 03ad0bcc>

circleReactor {Owners}
113

113

4.
vlr-owner-remove

(vlr-owner-remove reactor owner)

reactor owner
VLAVLA
(vlr-owner-remove circleReactor archie) #<vlaOBJECT IAcadArc 03ad0bcc>

11.4.3
1.
vlr-added-pvlradded-p
(vlr-added-p obj)
obj
AutoCAD T
nil
(vlr-added-p circleReactor) T

2.
vlr-removevlr-remove

(vlr-remove obj)

obj
nilcircleReactor

(vlr-remove circleReactor)#<VLR-Object-reactor>

2.
vlr-add
AutoCADvlr-add
(vlr-add obj)
obj
nil
circleReactor
(vlr-add circleReactor) #<VLR-Object-reactor>
vlr-remove-all
vlr-remove-all
(vlr-remove-all [reactor-type])

reactor-type
reactor-type

nil

(vlr-remove-all :vlr-editor-reactor) ((:VLR-Editor-Reactor


#<VLR-Editor-Reactor>))

(vlr-remove-all) ((:VLR-Object-Reactor #<VLR-ObjectReactor>


#<VLR-Object-Reactor>#<VLR-Object-Reactor>)
(:VLR-Editor-Reactor #<VLR-Editor-Reactor>))

11.5

1.

vlr-pers
vlr-pers
(vlr-pers obj)
obj
nil
(vlr-pers circleReactor) ;#<VLR-Object-Reactor>

2.
vlr-pers-releasevlrpers

(vlr-pers-release obj)
obj nil
(vlr-pers-release circleReactor) ;#<VLR-Object-Reactor>

3.
vlr-pers-pvlr-pers-p

(vlr-pers-p obj)
obj
nil
(vlr-pers-p circleReactor) ;#<VLR-Object-Reactor>

4.
vlr-pers-list
vlr-pers- list
(vlr-pers-list [reactor-type])
reactor-typereactorrtype

(vlr-pers-list) ; (#<VLR-Object-Reactor> #<VLR-Object-Reactor>


(#<VLR-Object-Reactor>)

5.

AutoCAD

VLX

VLISP
AutoCADvlrpers-list

11.6

OPEN BeginCommand BeginOpen


EndOpen EndCommand
BeginEnd
commandWillStart()commandEnded()
beginInsert()endInsert()

A :vlr-erased A
A :vlr-erased B :vlrerasedABB
A
AutoCAD

AutoCAD
getpointentselgetkword
command

(4)
AutoCAD

(5)

AutoCAD

(6)

BeginOpen
AutoCAD

(7)

(8)

11.7
1.

11-4:vlrmodified

11-4
(vl-load-com)
(defun c:rct-line(/ el rlt vrl)
(setq el(car (entsel "\n:")))
(setq rlt(list (vlax-ename->vla-object el)));VLA

;show-l

(setq vrl (vlr-pers(vlr-object-reactor rlt


show-l)))))

nil '((:vlr-modified .

(princ)
)
;

(defun show-l(notifier-object reactor-object parameter-list / l)

(setq l(vla-get-length notifier-object));l


(setq l(rtos l 2 4));

(alert (strcat "" l));


)

Commandrct-line

114

114

2. 115

115

11-4:vlr-modified

11-5

(vl-load-com)

(defun c:c1l2( / p0 p1 p2 p3 p4 r r1 eh1 eh2 l1-l2 rlt vrl)


(setq p0(getpoint "\n"))
(setq r(getdist p0 "\n"))
(command "circle" p0 r)
(setq r1(* 1.25 r))
(setq ec(entlast))
(setq p1(polar p0 0 r1))

(setq p2(polar p0 (* 0.5 pi) r1))


(setq p3(polar p0 pi r1))

(setq p4(polar p0 (* -0.5 pi) r1))


(command "line" p1 p3 "")
(setq eh1(cdr (assoc 5 (entget (entlast)))));
(command "line" p2 p4 "")
(setq eh2(cdr (assoc 5 (entget(entlast)))));

(setq l1-l2(list eh1 eh2));


(setq rlt(list (vlax-ename->vla-object ec)));VLA

(setq vrl (vlr-pers(vlr-object-reactor rlt l1-l2 '((:vlr-modified . c2l)))));


c-2l

(princ);
)

;c-2l

(defun c-2l(notifier-object reactor-object parameter-list / ec ec_l


el1 el2 ell_1 ell_2 p0 p1 p2 p3 p4 p0x p0y p0z)
(setq ec(vlax-vla-object->ename notifier-object);VLA

ec_l(entget ec);

p0(cdr(assoc 10 ec_l));
r(* 1.25 (cdr(assoc 40 ec_l)));1.25
)
(setq el1(handent (car (vlr-data reactor-object))));

(setq el2(handent (cadr (vlr-data reactor-object))));

(setq p0x (car p0));X


(setq p0y (cadr p0));Y
(setq p0z (caddr p0));Z
(setq p1 (list (+ p0x r) p0y p0z));
(setq p2 (list p0x (+ p0y r) p0z));
(setq p3 (list (- p0x r) p0y p0z));

(setq p4 (list p0x (- p0y r) p0z));


(setq ell_1(entget el1));

(setq ell_1(subst (vl-list* 10 p1)(assoc 10 ell_1)ell_1));

(setq ell_1(subst (vl-list* 11 p3)(assoc 11 ell_1)ell_1));

(entmod ell_1);
(setq ell_2(entget el2));
(setq ell_2(subst (vl-list* 10 p2)(assoc 10 ell_2)ell_2));

(setq ell_2(subst (vl-list* 11 p4)(assoc 11 ell_2)ell_2));

(entmod ell_2);
)
Commandc1l2
115

VLA



AutoLISP

ActiveX
145ActiveX144
(vl-load-com)

(defun c:c1l2(/ p0 p1 p2 p3 p4 r ec el1 el2 v_c v_l1 v_l2 l1-l2 vrl)


(setq p0(getpoint "\n:"))

(setq r(getdist p0 "\n:"))


(command "circle" p0 r)
(setq r(* 1.25 r))
(setq ec(entlast))
(setq v_c(list (vlax-ename->vla-object ec)));VLA

(setq p1(polar p0 0 r))

(setq p2(polar p0 (* 0.5 pi) r))


(setq p3(polar p0 pi r))
(setq p4(polar p0 (* -0.5 pi) r))
(command "line" p1 p3 "")
(setq el1(entlast));
(setq v_l1(vlax-ename->vla-object el1));VLA

(command "line" p2 p4 "")


(setq el2(entlast));
(setq v_l2(vlax-ename->vla-object el2));VLA

(setq l1-l2(list v_l1 v_l2));VLA

(setq vrl (vlr-pers(vlr-object-reactor v_c l1-l2 '((:vlr-modified .


c-2l)))));VLA
c-2l

(princ)
)
;c-2l

(defun c-2l(notifier-object reactor-object parameter-list / p0 p1


p2 p3 p4 p0x p0y p0z l v_l1 v_l2)
(setq p0(VLA-get-center notifier-object));P0
(setq p0(vlax-variant-value p0));
(setq p0(vlax-safearray->list p0));
(setq c_r(* 1.25 (VLA-get-radius notifier-object)));
1.5

(setq v_l1(car (vlr-data reactor-object)));VLA

(setq v_l2(cadr (vlr-data reactor-object)));VLA


(setq p0x (car p0));X
(setq p0y (cadr p0));Y
(setq p0z (caddr p0));Z
;ActiveX

(setq p1 (vlax-3d-point (list (+ p0x c_r) p0y p0z)));


(setq p2 (vlax-3d-point(list p0x (+ p0y c_r) p0z)))
(setq p3 (vlax-3d-point(list (- p0x c_r) p0y p0z)))
(setq p4 (vlax-3d-point(list p0x (- p0y c_r) p0z)))

(vla-put-startpoint v_l1 p1);1


(vla-put-endpoint v_l1 p3);1

(vla-put-startpoint v_l2 p2);2


(vla-put-endpoint v_l2 p4);2
)
VLA
VLA

12

12.1
1.

DCLDialog Control Language


"DCLAutoLISPC
AutoCADDCL ACAD.DCL
AutoCAD BASE.DCL

2.
12-1

12-1

3.
12-1DCL
VLISP
ToolsInterface ToolPreview DCL in Editor12-2

sample:dialog {
label = "";

:text {label = "";}


:button{
key = "accept";

label = "";
is_default = true;
fixed_width = true;

alignment=centered;
}}

12-2

12.2
AutoCAD23
8

""button
label = " " key = "accept" is_default = true
fixed_width = truealignment = centered
12-2

12.2.1
(action)
AutoLISP

1. Button

OK

buttonactionalignmentfixed_height
fixed_width height is_cancel is_default is_enabled
is_tab_stopkeylabelmnemonicwidth 13
label
OK"accept"
is_defaulttrue121""

2. Edit Box
edit_boxaction
alignment allow_accept edit_limit edit_width
fixed_height fixed_width height is_enabled
is_tab_stop key label mnemonic value width
password_char 16
1212
value
12-3
:edit_box
{ key="test_text";
label=": ";

value="100.0";
width=12;
}

12-3

3. (Image Button)
AutoLISP
image_buttonactionalignmentallow_accept
aspect_ratio color fixed_height fixed_width height
is_enabledis_tab_stopkeymnemonicwidth 13
AutoLISP

12-4
:image_button
{ key="test_image_button";
width=10;

aspect_ratio=1.5;
}

12-4

4. List Bbox
list_box action alignment
allow_accept fixed_height fixed_width height
is_enabled is_tab_stop key label list mnemonic
multiple_selecttabsvaluewidth 16

0
multiple_selecttrue

12-5

12-5
:list_box

{label="";
list= "\n\n\n\n
\n\n";
value="2";

key="gear_list";
height=6;
}

12-5

5. Popup List
popup_listactionalignment

edit_width fixed_height fixed_width height


is_enabled is_tab_stop key label list mnemonic
tabsvaluewidth 15

12-6a
12-6b

12-6
:popup_list
{label="";
list="\n\n\n\n\n
\n";
key= "gear_list";
}

b
12-6

6. Radio Button
radio_buttonactionalignment
fixed_height fixed_width height is_enabled
is_tab_stopkeylabelmnemonicvaluewidth 12

12-7

:radio_button
{ key= "unit_mm";
label= "";
}

12-7

7. Slider

slider action alignment big_increment


fixed_heightfixed_widthheightkeylabellayoutmax_value
min_valuemnemonicsmall_incrementvaluewidth 15

max_value min_value
small_incrementbig_increment
12-8
:slider
{ key= "test_slider";
min_value=0;

max_value=100;
}

12-8

8. Toggle
toggle
actionalignmentfixed_heightfixed_widthheight
is_enabledis_tab_stopkeylabelvaluewidth 11

12-9
:toggle
{ label= "";
key= "ortho_mode";

value=1;
}

12-9

12.2.2

1. Column

columnalignmentchildren_alignment
children_fixed_heightchildren_fixed_width
fixed_heightfixed_widthheightlabelwidth 9

12-10

12-11

12-10

:edit_box{label= "y=";

:column{

width=12;

:button{label= " <";

key= "y";

key= "pick";

mnemonic= "y";

value=0.0;

:edit_box{label= "x=";
width=12;

}
}

key= "x";

mnemonic= "x";
value=0.0;
}
12-10

2. Boxed Column

boxed_bolumn alignment
children_alignment

children_fixed_height

children_fixed_widthfixed_heightfixed_widthheight
labelwidth 9

12-10 ":column{
:boxed_column{label= """
12-11

12-11

3. Radio Column

radio_columnalignmentchildren_alignment
children_fixed_height children_fixed_width fixed_height
fixed_widthheightlabelwidth 9
1

12-12

12-13

12-12

:radio_button{label= "A&4";

:radio_column{
key= "size";

key= "a4";}
:radio_button{label= "A&5";

:radio_button{label= "A&0";
key= "a0";}

key= "a5";}
}

:radio_button{label= "A&1 ";


key= "a1";}
:radio_button{label= "A&2 ";
key= "a2";}
:radio_button{label= "A&3";

key= "a3";
value=1;}

12-12

4. Boxed Radio Column

boxed_radio_columnalignment
children_alignment

children_fixed_height

children_fixed_width fixed_height fixed_width


heightlabelwidth 9
12-12
":radio_column{"

":boxed_radio_column{label="
""
12-13
12-13

5. Row

row alignment children_alignment


children_fixed_height children_fixed_width fixed_height
fixed_widthheightlabelwidth 9
12-14
:row{
:toggle{ label="";

12-14

key="dir"; }

:edit_box{ label="W(mm)="; mnemonic="W"; key="w";


value=420; }
:edit_box{ label="H(mm)="; mnemonic="H"; key="h";

value=297; }
}

6. Boxed Row

boxed_row alignment
children_alignment

children_fixed_height

children_fixed_widthfixed_heightfixed_widthheight
labelwidth 9

12-14 ":row{"
":boxed_row{label="""
12-15

12-15

7. Radio Row

radio_row alignment children_alignment


children_fixed_height children_fixed_width fixed_height
fixed_widthheightlabelwidth 9
1
12-16
:radio_row{

12-16

key="size";
:radio_button{label="A&0"; key="a0";}

:radio_button{label="A&1"; key="a1";}
:radio_button{label="A&2"; key="a2";}
:radio_button{label="A&3"; key="a3"; value=1;}

:radio_button{label="A&4"; key="a4";}
:radio_button{label="A&5"; key="a5";}
}

8. Boxed Radio Row

boxed_radio_row alignment
children_alignment

children_fixed_height

children_fixed_widthfixed_heightfixed_widthheight
labelwidth 9

12-16 ":radio_row{"
":boxed_radio_row{label="""
12-17

12-17

9. dialog

OKCancel
dialoginitial_focuslabelvalue 3
value
initial_focus

sample:dialog {
label = "";
:text {label = "";}

:button{key = "accept";
label = "";
is_default = true;
fixed_width = true;
alignment=centered;}
}

12.2.3

1. Image

imagealignmentaspect_ratiocolor
fixed_height fixed_width height is_enabled
is_tab_stopkeymnemonicwidth 11
AutoLISP

widthheightaspect_ratio
AutoLISP

12-18
:image{ width=30;
aspect_ratio=0.6;
key= "rect";
color=graphics_background;

AutoLISP
12-18

2. Text

textalignmentfixed_heightfixed_width
heightis_boldkeylabelvaluewidth 9
labelvalue
labelvalueAutoLISP
labelvaluelabel
12-2 label12-19
12-2 label
iwarn1:dialog{label="";
:text{label="";
}

ok_cancel;
}

12-19

3. text_part
text_partlabel
labelText
Text12-3
12-20
12-3

warn2:dialog{label="";
:text_part
{label=""; }
:text_part
{label=""; }
ok_cancel;
}

12-20

4. Concatenation
Concatenation

12-412-21
//12-4
Warn3:dialog{label="";

:concatenation
{ :text_part {label=""; }
:text_part { label=""; }
}
ok_cancel;
12-21
}

5. Paragraph
paragraph
12-512-22
warn:dialog{label="";
:paragraph{
:concatenation {
: text_part{ label=""; }
: text_part{ label=""; }
}

:text_part{label =" "; }


}
ok_cancel;

}
12-22

6. SpacerSpacer_0Spacer_1
Spacer

spaceralignmentfixed_heightfixed_width
heightwidth 5
Spacer_0Spacer_1AutoCAD Spacer_0Spacer
widthheight0Spacer_1Spacerwidthheight1
Spacer_0Spacer_1
12-2343,
3
Spacer_0Spacer_0
0
Spacer_11
4Spacer4
12-6

Spacer_0
Spacer_1
Spacer=4

12-23 spacerspacer_0spacer_1
12-6spacerspacer_0spacer_1
spcr:dialog{label= ;
:row{//
:button{label="A0";key="a0";fixed_width=true;}

:button{label="A1";key="a1";fixed_width=true;}
:button{label="A2";key="a2";fixed_width=true;}
}

:row{spacer_0;//Spacer_0
:button{label="B0";key="b0";fixed_width=true;}
:button{label="B1";key="b1";fixed_width=true;}
:button{label="B2";key="b2";fixed_width=true;}
}
:row{spacer_1;//Spacer_1

:button{label="C0";key="c0";fixed_width=true;}
:button{label="C1";key="c1";fixed_width=true;}
:button{label="C2";key="c2";fixed_width=true;}
}

:row{:spacer{//4Spacer

width=4;
fixed_width=true;

}
:button{label="D0";key="d0";fixed_width=true;}
:button{label="D1";key="d1";fixed_width=true;}
:button{label="D2";key="d2";fixed_width=true;}
}
ok_cancel_help_info;
}

12.2.4 AutoCAD
AutoCAD258
AutoLISP

1. ok_only
OK"accept"
2. ok_cancel
OKCancelOKCancel
"cancel"Cancel
3. errtile

ErrtileText"error"
valuevalueAutoLISP

12-712-24AutoLISP

// DCL12-7.dcldexample\dcl
error:dialog{label=""

errtile
ok_only
}

12-24
; AutoLISP12-7.lsp
(defun c:erdlg()
(if (< (setq id(load_dialog "d:example\\dcl\\12-7")) 0) (exit))
(if (not (new_dialog "error" id))(exit))
(set_tile "error" " 0 ")
(action_tile "accept" "(done_dialog)")
(start_dialog)
(unload_dialog id)
(princ)
)

4. ok_cancel_help
OKCancelHelpOKCancel
Help"help"
12-812-25"OK""Cancel""Help"
AutoLISP
//DCL12-8.dcldexample\dcl

hlp:dialog{
label = "";
ok_cancel_help;
}

12-25 ok_cancel_help

AutoLISP12-8.lsp
(defun c:hlpdlg()
(setq id(load_dialog "d:\\example\\12-8.dcl"))

(if (< id 0)(exit))


(if (not (new_dialog "hlp" id))(exit))
(action_tile "help" "(help \"\" \"line\")") help
AutoLISPhelp

(action_tile "accept" "(done_dialog)")


(action_tile "cancel" "(done_dialog)")
(start_dialog)
(unload_dialog id)

(princ)
)

5. ok_cancel_help_errtile

OKCancelHelp3
4errtile

AutoLISPset_tilevalue

(set_tile "error" "")

//ok_cancel_help_errtileerror.dcl

error:dialog{label="";
ok_cancel_help_errtile;
}
(defun c:erdlg() AutoLISP
(if (< (setq id(load_dialog "d:\\example\\dcl\\error")) 0) (exit))

(if (not (new_dialog "error" id))(exit))


(set_tile "error" "")
(action_tile "accept" "(done_dialog)")
(start_dialog)
(unload_dialog id)

(princ)
)

6. ok_cancel_help_info

OKCancelHelpinfo,OK
CancelHelpinfo"info"
AutoLISPinfo
text

12.3

".1""0.1"

AutoLISP"\"
truefalseleftcenteredrighttopbottom
AutoLISP

AutoCAD35

1. action
AutoLISP
AutoCADAutoLISP
AutoLISPDCL

buttonedit_boximageimage_buttonlist_box
popup_listradio_buttonslidertoggle

2. alignment
left
centeredrighttop
centeredbottom

leftcentered

3. allow_accept
trueEnter
is_default true
edit_boximage_buttonlist_box
false

4. aspect_ratio

imageimage_button

5. big_increment
min_value
max_value
slider
1/10

6. children_alignment
alignment
alignment
boxed_columnboxed_radio_columnboxed_radio_row
boxed_rowcolumnradio_columnradio_rowrow
leftcentered

7. children_fixed_height
fixed_height
fixed_height
boxed_columnboxed_radio_columnboxed_radio_row

boxed_rowcolumnradio_columnradio_rowrow
false

8. children_fixed_width
fixed_ width
flasefixed_ width

boxed_columnboxed_radio_columnboxed_radio_row
boxed_rowcolumnradio_columnradio_rowrow

false

9. color
AutoCAD
redyellow12-1

imageimage_button
7

12-1

-2

Graphics_background

-15

Dialog_background

-16

Dialog_foreground

-18

Dialog_line Current

10. edit_limit
256
edit_box

132

11. edit_width
0

edit_boxpopup_list

12. fixed_height
trueheight

flase

13. fixed_width

fixed_width = true;

fixed_width = false;

width = 10;

width = 10;

truewidth

flase

12. fixed_width_font
true

list_boxpopup_list

flase

15. height

Flase

ture

fixed_heighttureheight

16. initial_focus

dialog

17. is_bold
true
text
false

18. is_cancel
trueEsc
is_canceltrue

button
false

19. is_default
trueEnter
true

button
false

20. is_enabled
true
buttonedit_boximageimage_buttonlist_box
popup_listradio_buttontoggle
true

flase

ture

21. is_tab_stop
"Tab"falseTab

buttonedit_boximageimage_buttonlist_box
popup_listradio_buttontoggle
true

22. key

AutoLISP

Buttonedit_boximageimage_buttonlist_box
popup_listradio_buttonslidertexttoggle

23. Label

label

boxed_columnboxed_radio_columnboxed_radio_row
boxed_row button dialog edit_box list_box popup_list
radio_buttonslidertexttext_parttoggle

24. layout
sliderhorizontalvertical
horizontal
slider
horizontal

25. list
"\n"
"\t"
list_boxpopup_list

26. max_value
-3276832767
slider
10000

27. min_value
-3276832767
slider
0

28. mnemonic

label"&"
is_tab_stop
true
buttonedit_boximagelist_boxpopup_list
radio_buttonslidertoggle

29. multiple_select
true
list_box
false

30. password_char

edit_box

31. small_increment
min_valuemax_value
slider

1/100

32. tabs
"\t"
list_boxpopup_list

33. tab_truncate
truetabstabs

list_boxpopup_list
false

34. value

valuevalue
value1value
AutoLISP
dialogedit_boximagelist_boxpopup_list
radio_buttonslidertexttoggle

35. width

fixed_widthturewidth

12.4

12.4.1
1.

2.

XYZ

3.

4.

AutoCAD

5.
12-26

12-26

6.

7.

errtile
alert

8.
""

Help
Helpacad_help.dlg
AutoCADHelp

9.

12.4.2
1.

Tab

2.

3.

4.

""

5.
"<"

6.

7.
Tab

8.
AutoCAD

9.
AutoCAD"OK""Cancel"

12.4.3
1. (Button)

"""<"

2. (Edit box)
""

1020
text

3. (List box)
1
2

3
4

4.
1""

216

5.
1

2
6.

24

7. (slider)
text

8.

9.

10.

""""

12.5
DCL

12.5.1
DCLASCII
".dcl"DCL
1. base.dclacad.dcl
AutoCADsupport
1BASE.DCL
ButtonEdit boxRowColumn
ok_cancelok_cancel_help_infoDCL
DCL
2ACAD.DCL
ACAD.DCLAutoCADDCL
ACAD.DCL
ACAD.DCLDCL
AutoCAD

2.

1DCL@include "\\DCL"
DCL@include "test.dcl"
12-27DCLuser1.dcl

user2.dcluser3.dcluser1.dcl

12-27 DCL

12.5.2 DCL
12-28row
ok_cancel
12-29

12-28

12-29

12-29

12-912-28DCL"129.dcl"dexample\dcl\
12-912-28

yuan:dialog{ //yuan
label= "";//
:row{ //
:image //
{width=30;//

height=8;//
key="img_cr";//

12-28

color=-2;//AutoCAD
}//

:boxed_column{//
label="";//
:edit_box{ //1

label="X(mm)"; //1
edit_width=8; //1
key="X";//1
mnemonic="X";//1
}//1
:edit_box{ //2
label="&Y(mm)"; //2&
width=8; //2

key="Y";//2
}//2

:edit_box{ //3
label="R(mm)"; //3
width=8; //3
key="R";//3

mnemonic="R";//3
}//3

}//
}//

ok_cancel;// ok_cancel
}

12.5.3 DCL
1.
C

name:item1 [:item2 :item3] {


attribute1=value1;
attribute2=value2;

nameitem1name:item
nameitemattribute1item
value1"{ attribute1=value1;}"item1
value1attribute1itemattribute1
attribute1name"{ }"

name item1 item2


attribute1attribute2
attribute1attribute2value1value2
name

button:
button:tile{fixed_height=true;
is_tab_stop=true;
}
base.dcldefault_buttonbutton:
default_button:button { is_default=true;
}
default_buttonbuttonfixed_heightis_tab_stop
is_defaulttrue

AutoCAD

2.

DCLDCL

:
1""

ok_cancel_help;
OKCancelHelp
2""

:edit_box{ //
label="Y(mm)"; //

width=8; //
key="Y"}

"Y(mm)
"8"Y"

3.
attribute=value

attributevalue""

4.
DCLCC++"//"
"/*""*/"

12.6

AutoLISPVisual C++

12.6.1

12-30

12-30

1.
AutoLISPload_dialog

2.
new_dialog

3.
set_tile
mode_tileaction_tile

4.
start_dialog
done_dialog

5.

get_tileget_attrset_tilemode_tile

6.
OKCencalExit
done_dialog
unload_dialog

7.

OKCencal
done_dialogOK
OK
Cencal

12.6.2
1.
(1)load_dialog

dclfilename

dclfilename
.dclAutoCAD

setq

dcl_id

(load_dialog

"d:\\user\\test.dcl")

dcl_id
(2)unload_dialog

dcl_id

dcl_id
dcl_idload_dialog
nil
unload_dialog

dcl_id

2.
(1)new_dialog dlgname dcl_id [action [screen_pt]]
dlgnamedcl_id
actionscreen_pt
Action
screen_pt
T
"yuan"
dcl_idload_dialog

new_dialog

"yuan"

dcl _id

"rect"
a1dcl_idload_dialog
(new_dialog

"rect"

dcl _id

"(setq a 1)" (0 0))

(2)start_dialog
new_dialog
done_dialog
done_dialog
start_dialognew_dialogT

(3)done_dialog

[status]

statusstart_dialog

(4)term_dialog

AutoCAD
nil

3.
action_tile

key

action_expression

keyaction_expression

action_tile

"accept"

" "(usrt_function)(dine_dialog 1)"

""usrt_function1
usrt_function

action

4.
(1) (mode_tile

key

mode)

keymode
0

34

(mode_tile "button_1" 1)button_1


(mode_tile "button_1" 0)button_1
(2)get_attr

key

attribute

keyattribute

(setq w(get_attr
w

"img" "width")) img

(3)get_tile key
keyvalue

setq s1(get_tile "edt1")edt1


s1

(4)set_tile key value

key
(set_tile "edt1" "50.0") edt1"50.0"
5dimx_tile key
key
6dimy_tile key
key

5.
listDCL

(1)(start_list

key

operation

[index]

keyopreation
opreation123
Opration3index
0 0
(2)(add_list

item)

start_listopration
opration=1itemindexindex

opration=2item
opration=3item

(3) end_list

12-10AutoLISP12-5
(setq gear(list "" "" "" "" "
" ""))
(start_list "gear_list") gear_list
(mapcar 'add_list gear)

(end_list)

6.
DCLAutoLISP

(1) (start_image

key)

key

(2) vector_image

x1

y1

x2

y2

color

x1y1x2y2color
x1y1x2y2
00dimx_tile
(dimy_tile)ColorAutoCAD
12-1
(3) (fill_image

x1

y1

x2

y2

color)

x1y1x2y2
colorvector_imagex1y1x2y2

(4) slide_image

x1

y1

x2

y2

sldname

,
.sld.slb
x1y1x2y2vector_imagex1y1
(x2y2)
AutoCADmslide
sldname
5end_ image

12-11AutoLISP12-18
(start_image

(setq max_x

"rect") ;rect

(dimx_tile "rect"));x

(setq max_y

(dimy_tile "rect"));y

(slide_image 0 0 max_x max_y " test");


"test.slg"

(end_image);
12-18

7.

client_data_tile key clientdata


keykey
clientdatakey
$datanil

12.6.3 AutoLISP
1. (alert "")
"OK"
(alert "15 ")
12-31

12-31

2. (acad_colordlg [])
AutoCAD0 2560
byblock256bylayer
nilbylayerbyblock
(setq c(acad_colordlg 1 T))
12-32AutoCAD

3
c

12-32

3. (getfiled "" "" "" 0))

""""
"dwg"

015
1001

4 201

830
10

1641

325101

6461URL
12871 URL

12-33test
"d:\\example\\lisp\\test.lsp"a
(setq a(getfiled "LISP" "d:\\example\\lisp\\" "lsp" 1))

12-33

4. (help [ [ [command]]])
helpfile
AutoCADcommand

HELP_CONTENTS

HELP_HELPONHELP

""

HELP_PARTIALKEY

helpfilenil
help nil
helpcircle 12-34

(help "" "circle")

12-34 helpcircle

12.6.4
callbackaction
LISP

1.

(1) $key
(2) $value
(3) $datanew_dialogclient_data_tile

(4) $reason

2
3
4

(5) $xx
(6) $yy

(action_tile "edit1" "(setq v1 $value)") edit1


edit1v1

(action_tile $key "(setq v2 $value)")


v2

(action_tile "edit2" "(setq v3 $reason)")edit2


edit2v3

(action_tile "img_button" "(setq x1 $x y1 $y)")


img_buttonX
x1, Yy1

2.
1
OK
key"accept"
done_dialog

(action_tile

"accept" "(getdata)(done_dialog 1)")

getdata
1done_dialog
2cancel key
"cancel"done_dialog

(action_tile

"cancel" "(done_dialog 0)")

0done_dialog
Start_dialogdone_dialog
OK1Cancel0

3. AutoLISP

AutoLISP

1AutoCAD
command
2
get gr osnap menucmd prompt redraw textpage
textscr
3
entnentsel

12-12

12-9.dcld
example\dcl\
yuan
12-12
;12-12.lsp
(defun c:drawcirc( / xc yc r id x1 y1 ) ;drawcirc

AutoCAD

(defun getdata();getdata
(setq xc(atof(get_tile "X")));Xxc

(setq yc(atof(get_tile "Y"))) ;Yyc


(setq r(atof(get_tile "R")));Rr
)

(setq sdt 0);sdt0


(setq id(load_dialog "d:\\example\\dcl\\12-9.dcl"));DCL
12-9

(if (< id 0)(exit)) ;


(setq

xc 50.0 yc 50 r 25);

(if (not (new_dialog "yuan" id))(exit));yuan

(setq x1(dimx_tile "img_cr"));img_cr


(setq y1(dimy_tile "img_cr"));
(start_image "img_cr");
(slide_image 0 0 x1 y1 "d:\\example\\sld\\12-12");
12-12
(end_image);

(set_tile "X" (rtos xc 2 2)) ;X


(set_tile "Y" (rtos yc 2 2)) ;Y
(set_tile "R" (rtos r 2 2)) ;R
;dcl3

(action_tile "accept" "(getdata) (done_dialog 1)") ;OK


getdata,1

(action_tile "cancel" "(done_dialog -1)");Cancel


-1

(setq sdt (start_dialog));,

(unload_dialog id);
(if (> sdt 0);
(command "circle" (list xc yc)
(princ)
)

r)) ;OK

AutoLISP"drawcirc

12.6.5
1. /

12-9

done_dialog
new_dialog
""

1""done_dialog"""
"
2

50100""

12-13
LISPDCL1235
"

<"
OK

1235

12-13
(defun c:shaft( / d l x y id std x1 y1)
(defun getdata() ; DLxy

(setq d(atof(get_tile "D_box")))


(setq l(atof(get_tile "L_box")))
(setq x(atof(get_tile "X_box")))

(setq y(atof(get_tile "Y_box")))


) getdata
(setvar "cmdecho" 0)
(command "layer" "m" "solid" "")
(command "layer" "m" "cen" "c" 1 "" "lt" "center" "" "")
(setq id(load_dialog "d:\\example\\dcl\\12-13")) ;"1213.dcl"

(if (< id 0)(exit))

(setq d 50 l 100 x 0 y 0 std 2 p (list 0 0))


(while (> std 1)while
(if (not (new_dialog "zhou" id))(exit))
(setq x1(dimx_tile "image")) ;x1
(setq y1(dimy_tile "image")) ; y1
(start_image "image") ;

(slide_image 0 0 x1 y1 "d:\\example\\sld\\12-13");
12-13.sld

(end_image) ;

(set_tile "D_box" (rtos d 2 2)) ;


(set_tile "L_box" (rtos l 2 2))
(set_tile "X_box" (rtos x 2 2))

(set_tile "Y_box" (rtos y 2 2))


(action_tile "pick" "(getdata)(done_dialog 2)" );

(action_tile "accept" "(getdata)(done_dialog 1)" );OK


(action_tile "cancel" "(done_dialog 0)" ) ;Cancel
(setq std(start_dialog))
(if(= std 2);""while
(progn

(initget 1)
(setq p(getpoint ":"))p
(setq x (car p) y (cadr p))pXYxy
)
)
)while

(if ( std 1)OK


(progn
(command "layer" "m" "solid" "")
(command "pline"
(list x (+ y (* 0.5 d)))
(list x (- y (* 0.5 d)))

(list (+ x l) (- y (* 0.5 d)))


(list (+ x l) (+ y (* 0.5 d)))
"c")
(command "layer" "m" "cen" "")
(command "line" (polar p pi 10) (polar p 0 (+ l 10)) "")
)
)
(unload_dialog id);

(princ);
)

OKCanceldone_dialog

OKgetdata

OKCanceldone_dialog
210start_dialogstdwhile
std=2
OKCancel
(set_tile "D_box" (rtos d 2 2)) d
D_box
(setq x (car p) y (cadr p))pXY
xy (set_tile "X_box" (rtos x
2 2)) pXYXY

12-13DCL12-13.dcl
zhou:dialog{//zhou
label= "";//
alignment=centered;
:row{//
:image{width=40; //
height=8;
key="image";
color=-2;
}
:column{//
:edit_box{label="&D(mm)"; //

key="D_box";
width=12;
}

:boxed_column {//
label="";//
:button{//
label=" <";
key="pick";

}
:edit_box{//
label="&X(mm)";
width=12;
key="X_box";

:edit_box{//
label="&Y(mm)";
width=12;

key="Y_box";
}

} //
} //

}//
ok_cancel;//OKCancel

2.

""""

new_dialog
start_dialog""""
""

""""
"

12-14
12-36""1237
LISPDCL

1236

1237

12-14
(defun initimg(image sld);image
sld

(start_image image)
(slide_image 0 0 (dimx_tile image) (dimy_tile image) sld)
(end_image)
)
(defun dlg1();juxing
(if (not (new_dialog "juxing" id))(exit))

(initimg "rect1"

"d:/example/sld/12-14-1");

12-14-1.sld

(set_tile "l_box" (rtos l 2 2))

(set_tile "w_box" (rtos w 2 2))


(action_tile "base" "(getdata1)(dlg2)") ;1

(action_tile "accept" "(getdata1)(done_dialog 1)");OK1

(action_tile "cancel" "(done_dialog 0)");cancel


)

(defun dlg2();zxjdian
(if (not (new_dialog "zxjdian" id))(exit))
(initimg

"rect2"

"d:/example/sld/12-14-2");

12-14-2.sld

(if (= sdt 4) (setq x x1 y y1));cancel


(set_tile "x_box" (rtos x 2 2))
(set_tile "y_box" (rtos y 2 2))
(action_tile "pick" "(done_dialog 2)");
(action_tile "accept" "(getdata2)(done_dialog 3)");
OK

(action_tile "cancel" "(done_dialog 4)");cancel

(setq sdt(start_dialog))
(if (= sdt 2) (done_dialog 2));
)
(defun getdata1();
(setq l(atof(get_tile "l_box")))
(setq w(atof(get_tile "w_box")))

)
(defun getdata2();
(setq x(atof(get_tile "x_box")))
(setq y(atof(get_tile "y_box")))
(setq x1 x y1 y);
)
(defun c:rect(/ l w
(setvar "cmdecho" 0)

x y sdt p);rect

(setq id(load_dialog "d:/example/dcl/12-14")) ;d:/example/dcl/


"12-14rect.dcl"

(if (< id 0)(exit))


(setq sdt 3 l 20 w 10 x 0 y 0 x1 0 y1 0)
(while (> sdt 1);while
(dlg1)

(if (= sdt 2) (dlg2)) ;


(if (/= 2 sdt) (setq sdt (start_dialog)))
(if (= sdt 2);

(progn
(initget 1);
(setq p(getpoint "\n:"))

(setq x (car p) y (cadr p))


)));while

(if (= sdt 1);OK


(command "pline";
(list x y)
(list (+ x l) y)
(list (+ x l) (+ y w))

(list x (+ y w))
"c")
)
(unload_dialog id);
(princ);
)

12-14 DCL 12-14.dcl


d:example\dcl
juxing:dialog{label= "";//juxing
:row{
:image{width=35;
height=8;
key="rect1";
color=-2;
}

:column{
:edit_box{
label="&L(mm)";

key="l_box";
}

:edit_box{
label="&W(mm)";
key="w_box";
}
:button{

label=" ...";
key="base";
}
}
}

ok_cancel;
}//

zxjdian:dialog{ //zxjdian
label= "";
:row{
:image{
width=20;
height=4;
key="rect2";
color=-2;
}
:boxed_column{
label="";
:button{

label=" <";
key="pick";
}

:edit_box{
label="&X(mm)";
key="x_box";
}
:edit_box{

label="&Y(mm)";
key="y_box";
}
}
}

ok_cancel;
}

12.6

12-1513-38

//12-15.dcl

img_dlg:dialog{ //img_dlg
label= ""; //
initial_focus="gear1"; //gear1

:row{label="";
:image_button{key="gear1";
color=-2;
width=10;
height=3;}

13-1

:image_button{key="gear2";
color=-2;
width=10;
height=3;}
:image_button{key="gear3";

color=-2;
width=10;

height=3;}
}
ok_cancel;
}

13-1

12-15.lsp

(defun initimg(img_key

slide /

x1

y1);

(setq x1(dimx_tile img_key))

(setq y1(dimy_tile img_key))


(start_image img_key)
(slide_image 0 0 x1 y1 slide)
(end_image)
)

(defun c :img( / id x1 y1 g sdt) AutoCADimg


(setq g 1)
(setq id(load_dialog "d:\\example\\dcl\\12-15"))
(if (< id 0)(exit))
(if (not (new_dialog "img_dlg" id))(exit)

(initimg "gear1"

"d:\\example\\sld\\12-15-1")1

(initimg "gear2"

"d:\\example\\sld\\12-15-2")2

(initimg "gear3"

"d:\\example\\sld\\12-15-3")3

(action_tile "gear1" "(setq g 1)" ) 1


(action_tile "gear2" "(setq g 2)" ) 2
(action_tile "gear3" "(setq g 3)" ) 3
(action_tile "accept" "(done_dialog 1)" ) OK
(action_tile "cancel" "(done_dialog -1)") Cancel

(setq sdt(start_dialog))
(unload_dialog id)
(if (> sdt 0)( princ g))
(princ)
)

12-1612-3912-40

12-39

12-40

//12-16.dcl
lst_dlg:dialog{label= ""; //
:list_box{label=""; //
value="2"; //
key="gear_list"; //
height=6; //height-1
fixed_width_font=true;//
}
ok_cancel;
}

12-16.lsp
(defun c:lst(/ id gear sdt chilun)AutoCADlst
(setq chilun "2")
(setq id(load_dialog "d:\\example\\dcl\\12-16"))
(if (< id 0)(exit))
(if (not (new_dialog "lst_dlg" id))(exit))
(setq gear(list "" "" "" "" "

" ""))
(start_list "gear_list")
(mapcar 'add_list gear)geargear_list
(end_list)

(action_tile "gear_list" "(setq chilun $value) )" )


chilun

(action_tile "accept" "(done_dialog 1)" )


(action_tile "cancel" "(done_dialog -1)")
(setq sdt (start_dialog))
(unload_dialog id)

(if (> sdt 0) (print (nth (atoi chilun) gear)))


(princ)
)

//plst.dcl
pop_lst:dialog{label= "";
:popup_list{label="";
key="gear_list";
}
ok_cancel;
}

12-17 12-41

//12-17.dcl
radio:dialog{ //radio

label= ""; //
initial_focus="a3";//
:toggle{label="&V";key="ver";}//
:boxed_radio_row{label=""; //
:radio_button{label="A&0";key="a0";}//A0
:radio_button{label="A&1";key="a1";}//A1
:radio_button{label="A&2";key="a2";}//A2
:radio_button{label="A&3";key="a3";}//A3
:radio_button{label="A&4";key="a4";}//A4
:radio_button{label="A&5";key="a5";}//A5
}
ok_cancel;
}

12-17.lsp
(defun c:radio(/ id sdt l h h_v) AutoCADradio
(setq id(load_dialog "d:\\example\\dcl\\12-17"))
(if (< id 0)(exit))
(if (not (new_dialog "radio" id))(exit))
(action_tile "a0" "(setq l 1189 h 841)" )a0

(action_tile "a1" "(setq l 841 h 594)" ) a1


(action_tile "a2" "(setq l 594 h 420)" ) a2
(action_tile "a3" "(setq l 420 h 297)" ) a3
(action_tile "a4" "(setq l 297 h 210)" ) a4
(action_tile "a5" "(setq l 210 h 148)" ) a5
(action_tile "accept" "(setq h_v(get_tile \"ver\"))(done_dialog
1)" )
OK

(action_tile "cancel" "(done_dialog -1)") Cancel


(setq sdt(start_dialog))
(unload_dialog id)

(if (= h_v "1") (setq w l l h h w))


(if (> sdt 0)
(print (list l h h_v)))

(princ)
)

12-41

12-18

12-42
12-42
//12-18.dcl
sld:dialog{ //sld
label= ""; //
initial_focus="edit_l"; //

:row{
:text{ key="field"; //
is_bold=true; //

value=""; //
}

:button{label="&A"; //
key="area"; //
fixed_width=true; //

}}
:row{
:boxed_column{label="100 ~ 800"; //

:edit_box{label="&L :"; //
key="edit_l"; //
value=150;} //
:slider{ key="sld_l"; //
min_value=100; //
max_value=800; //
small_increment=1; } //
}

:boxed_column{label="50 ~ 400"; //
:edit_box{label="&W :"; //
key="edit_w"; //

value=100;} //
:slider{ key="sld_w"; //
min_value=50; //
max_value=400; //
small_increment=1;} //
}
}

ok_cancel;
}

12-18.lsp
(defun c:sld(/ ll ww len wid area ss id sdt) AutoCAD
sld

(setq

len 150 wid 100)

(setq id(load_dialog "d:\\example\\dcl\\12-18.dcl"))


(if (< id 0)(exit))

(if (not (new_dialog "sld" id))(exit))


(action_tile "edit_l" "(flength)" );
(action_tile "sld_l" "(fsldl)" );

(action_tile "edit_w" "(fwidth)" );


(action_tile "sld_w" "(fsldw)" );
(action_tile "area" "(farea)");
(action_tile "accept" "(done_dialog 1)" )OK
(action_tile "cancel" "(done_dialog 0)")Cancel

(setq sdt(start_dialog))
(unload_dialog id)
(if (> sdt 0) (princ (list " =" len
area)))

" =" wid " ="

(princ)
)

(defun flength( / ll)

(setq ll(atoi $value)) ;ll


(if (or (< ll 100)(> ll 1000))
(progn

;ll

(set_tile $key (get_tile "sld_l"))

(setq len(atoi $value))


)

(progn

;ll

(set_tile "sld_l"

(itoa ll))

(setq len ll)

)
)
)
(defun fsldl();
(set_tile "edit_l" $value) ;

(setq len(atoi $value))


)
(defun fwidth( / ww);
(setq ww(atoi $value)) ;ww

(if (or (< ww 50)(> ww 800))


(progn

;ww

(set_tile $key (get_tile "sld_w"))


(setq wid(atoi $value))
)
(progn ;ww
(set_tile "sld_w" (itoa ww))

(setq wid ww)


)

)
)

(defun fsldw(/ ss);


(set_tile "edit_w" $value) ;
(setq wid(atoi $value))
)
(defun farea()
(setq area(* len wid))
(setq ss (itoa area))
(setq ss (strcat " " ss))
(set_tile "field" ss) fieldss
)

12-42

13

13 .1




CAD

13.1.1
1.
10
1
13-1.dcld:example\dcl\
main_dlgchildren_dlg
2AutoLISP

13-1.lsp
AutoLISP
3

13-1scr0.sld13-1scr1.sld13-1scr2.sld
13-1scr3.sld 13-1screw0.sld 131screw1.sld13-1screw2.sld13-1screw3.sldd:example\sld\

2.
1
13-1.lsp
2
command:screw13-1

13-1

3
13-1
13-2

13-2

4
d
d
L
L

dL
d
L
d
L

<

AutoCAD

text

6
4
4

OK

13.1.2
13-1
//main_dlg(row)

main_dlg:dialog{
label=":";
:row{ //
:boxed_column{ //
label=:;
:row{ //
:image_button{ //1

color=-2;
width=15;

aspect_ratio=0.66;
key="screw_0";}
:image_button{ //2
color=-2;
width=15;
aspect_ratio=0.66;
key="screw_1";}

}//
:row{ //

:image_button{//3
color=-2;width=15;aspect_ratio=0.66;key="screw_2";}

:image_button{//4
color=-2;

width=15;
aspect_ratio=0.66;
key="screw_3";}
}}//
:list_box{label = ""; //

list="GB/T 65-2000\nGB/T 68-2000\nGB/T


5780-2000\nGB/T 70.1-2000";//
key = "s_type";
width=15;
fixed_width=true;}//
} //

:row{ //
spacer_1; //
:button{label="";

key="accept";
is_default=true;
fixed_width=true;} //""
:button{label=;
key="cancel";
fixed_width=true;} //""
spacer_1; //

}//"accept""cancel"
} //main_dlg

//children_dlg(row)

children_dlg:dialog{
label="";
:row{ //
:image{color=-2;
width=22;

aspect_ratio=0.6;
key="id_img";}//
:list_box{label = &d; //

key = "s_d";
edit_width =5;
height=8;
list="M1.6\nM2\nM2.5\nM3\nM4\nM5\nM6\nM8\nM10\nM12\nM14\nM16\nM20";

fixed_height=true;}//
:list_box{label = "&L"; //
key = "s_l";
edit_width =5;
height=8;

list="2\n2.5\n3\n4\n5\n6\n8\n10\n12\n(14)\n16\n\20\n\25\n30\n35\n\
40\n45\n50\n";
fixed_height=true;}//

}//
:row{//
:column{//
:boxed_column{label="";//

:edit_box{label = &x:;//x
key = "p_x";
edit_width =8;
value="150";}
:edit_box{label = &y:;//y
key = "p_y";
edit_width =8;
value="100";}
:button{label = <;//
key = "p_p";}}
:boxed_column{label="";//
:edit_box{label = &Angle:;//alf

key = "alf";
edit_width =8;
value="0";}

:button{label = "<";
key = "p_a";}}
ok_cancel;//OKCancel

}//
:column{//
:boxed_column{//
:toggle{label="";//
key="user_dim";

value="0";}
:edit_box{label = "&d:";
key = "user_d";
edit_width =8;
value="10";}

:edit_box{label = "&L:";
key = "user_l";
edit_width =8;

value="50";}}
:boxed_column{//
:toggle{label="";//
key="cenline";
value=1;}

:row{//
:text{value="";}
:image_button{color=3;
height=2;
key="ccolor";}}

:row{//
:text{value="";}
:image_button{color=4;height=2;key="tcolor";}}
:row{//
:text{value="";}

:image_button{color=5;height=2;key="scolor";}}
} //

}//
} //
}// children_dlg
//

13.1.3 AutoLISP
1.
1 screwscrewAutoCAD

2initdlg1
3initdlg2s_t
4f_img
key
5c_cAutoCAD
6c_img
keycolor
7f_stype

8f_user

user_md

9getdata
10drarscrews_tdlp0
alfcen_mdcctc

sc
11drawwhorls_t
p0dlalfcen_mdcc

tcsc

2.
sdts_tdl
s_d_lists_l_listp0:xy:
alfd_nl_ncctc

scuser_mdd1
l1cen_md

3.
13-1SCREW
13-1.dcl

;AutoLISP
(defun c:screw(/ sdt d l x y p0 alf d_n l_n cc tc sc user_md d1 l1
cen_md)
;
(setq sdt 2 s_t "0" d 10 l 50 x 200 y 100 alf 0 d_n "5" l_n "7"
cc 3 tc 4 sc 5 user_md "0" d1 10 l1 50 cen_md "1"
p0 (list
x y))
(setq s_d_list (list 1.6 2 2.5 3 4 5 6 8 10 12 14 16 20))

(setq s_l_list (list 2 2.5 3 4 5 6 8 10 12 14 16 20 25 30 35 40


45 50))

;
(defun initdlg1 ()
(if(not (new_dialog "main_dlg" id))(exit))

(f_img "screw_0" "d:\\example\\sld\\13-1scr0");


(f_img "screw_1" "d:\\example\\sld\\13-1scr1")
(f_img "screw_2" "d:\\example\\sld\\13-1scr2")

(f_img "screw_3" "d:\\example\\sld\\13-1scr3")


;
(action_tile "screw_0" "(setq s_t \"0\")(set_tile \"s_type\"
\"0\")")
(action_tile "screw_1" "(setq s_t \"1\")(set_tile \"s_type\"
\"1\")")

(action_tile "screw_2" "(setq s_t \"2\")(set_tile \"s_type\"


\"2\")")

(action_tile "screw_3" "(setq s_t \"3\")(set_tile \"s_type\"


\"3\")")
(action_tile "s_type" "(f_stype )") ;
(action_tile "accept" "(done_dialog 2)") ;
(action_tile "cancel" "(done_dialog 0)") ;
(mode_tile "screw_0" 2);"screw_0"

(set_tile "s_type" "0");


(setq sdt (start_dialog))
)
;

(defun initdlg2 (s_t)


(if(not (new_dialog "children_dlg" id))(exit))
(setq sldname (strcat "d:\\example\\sld\\14-13screw" s_t));

(f_img "id_img" sldname);


(c_img "ccolor" cc);
(c_img "tcolor" tc)
(c_img "scolor" sc)
(set_tile "p_x" (rtos x 2 2));x
(set_tile "p_y" (rtos y 2 2))

(set_tile "alf" (rtos alf 2 2))


(set_tile "user_d" (rtos d1 2 2))
(set_tile "user_l" (rtos l1 2 2))
(set_tile "user_dim" user_md);
(f_user user_md);
(set_tile "cenline" cen_md);
(action_tile "p_p" "(getdata)(done_dialog 3)") ;

(action_tile "p_a" "(getdata)(done_dialog 4)");

(action_tile "ccolor" "(setq cc (c_c cc)) (c_img $key cc)");

(action_tile "tcolor" "(setq tc(c_c tc))(c_img $key tc))")


(action_tile "scolor" "(setq sc(c_c sc))(c_img $key sc))")
(action_tile

"user_dim"

"(f_user

(get_tile

\"user_dim\"))

(getdata)");
(action_tile "accept" "(getdata)(done_dialog 1)");

OK

(action_tile "cancel" "(done_dialog -1)");

(setq sdt (start_dialog))


)

Cancel

;
(defun f_img (key sld)
(start_image key)
(slide_image 0 0 (dimx_tile key) (dimy_tile key) sld)
(end_image)

)
;AutoCAD
(defun c_c(color / ccc)
(setq ccc(acad_colordlg color nil))
(if (not ccc) (setq ccc color))

ccc
)

;
(defun c_img (key color)
(if color

(progn
(start_image key)
(fill_image 0 0 (dimx_tile key) (dimy_tile key) color)
(end_image)
)

)
)
;
(defun f_stype ()
(setq s_t (get_tile "s_type"));s_t

(setq img_key (strcat "screw_" s_t)) ;


(mode_tile img_key 2);
)
;

(defun f_user (user_md)


(if

(= user_md "0")

(progn ;
(mode_tile "user_d" 1);
(mode_tile "user_l" 1);
(mode_tile "s_d" 0);
(mode_tile "s_l" 0);
(set_tile "s_d" d_n);
(set_tile "s_l" l_n);
)

(progn ;
(mode_tile "s_d" 1);
(mode_tile "s_l" 1);
(mode_tile user_d 0);
(mode_tile "user_l" 0);
(set_tile "user_d" (rtos d1 2 2));
(set_tile "user_l" (rtos l1 2 2));
)
)
)

;
(defun getdata ()
(setq l_n (get_tile "s_l"));

(setq d_n (get_tile "s_d"));


(setq x (atof (get_tile "p_x")));x
(setq y (atof (get_tile "p_y")));y
(setq alf (atof (get_tile "alf")));alf
(setq user_md (get_tile "user_dim"));
(setq d1 (atof (get_tile "user_d")));
(setq l1 (atof (get_tile "user_l")));
(setq cen_md (get_tile "cenline"));

(setq p0 (list x y))


)

(if (< (setq id (load_dialog "d:\\example\\dcl\\14-13.dcl")) 0)


(exit));
(initdlg1);
(while (> sdt 1);while
(initdlg2 s_t);
(if (= sdt 3)
(progn ;
(initget 1);
(setq p0 (getpoint ": "))

(setq x (car p0) y (cadr p0))


)
)

(if (= sdt 4)
(progn;

(if (= sdt 4)
(progn;
(initget 1);
(setq ang (getangle p0 ": "))
(setq alf (* 180.0 (/ ang pi)))
)));while
(unload_dialog id);

(if (= user_md "0")


(setq d (nth (atoi d_n) s_d_list) l(nth (atoi l_n) s_l_list));

(setq d d1 l l1);
)
(if (= sdt 1) ;
(drawscrew s_t d l p0 alf cen_md cc tc sc)
)
(princ))

;
(defun drawscrew(s_t d l p0 alf cen_md cc tc sc / p1 p2
p3 p4 p5 p6 p7 p8 p9 p10)

(setvar "osmode" 0)
(setvar "cmdecho" 0)

(setq alf (/ (* pi alf) 180));


(command "color" sc)

(if (= s_t "0"); GB/T65-2000


(progn

(setq p1 (polar p0 (+ alf (* 0.5 pi)) (* 0.75 d)))


(setq p2 (polar p1 (+ alf pi) (* 0.6 d)))

(setq p3 (polar p2 (+ alf (* -0.5 pi)) (* 0.65 d)))


(setq p4 (polar p3 alf (* 0.25 d)))
(setq p5 (polar p4 (+ alf (* -0.5 pi)) (* 0.2 d)))
(setq p6 (polar p5 (+ alf pi) (* 0.25 d)))
(setq p7 (polar p6 (+ alf (* -0.5 pi)) (* 0.65 d)))
(setq p8 (polar p7 alf (* 0.6 d)))
(command "line" p1 p2 p3 p4 p5 p6 p7 p8 "c")
(drawwhorl s_t p0 d l alf cen_md cc tc sc)
)
)

(if (= s_t "1");GB/T 68-2000


(progn
(setq p01(polar p0 alf (* 0.5 d)))
(setq p1 (polar p01 (+ alf (* 0.5 pi)) (* 0.5 d)))
(setq p2 (polar p1 (+ alf (* 0.75 pi)) (* 0.707107 d)))
(setq p3 (polar p2 (+ alf (* 1.5 pi)) (* 0.9 d)))

(setq p4 (polar p3 alf (* 0.25 d)))


(setq p5 (polar p4 (+ alf (* -0.5 pi)) (* 0.2 d)))
(setq p6 (polar p5 (+ alf pi) (* 0.25 d)))

(setq p7 (polar p6 (+ alf (* -0.5 pi)) (* 0.9 d)))


(setq p8 (polar p1 (+ alf (* -0.5 pi)) d))
(command "line" p1 p2 p3 p4 p5 p6 p7 p8 "c")

(drawwhorl s_t p01 d (- l (* 0.5 d)) alf cen_md cc tc sc)


)
)

(if (= s_t "2"); GB/T 5780-2000


(progn
(setq p1 (polar p0 (+ alf (* 0.5 pi)) (* 0.5 d)))
(setq p2 (polar p1 (+ alf (* 0.5 pi)) (* 0.5 d)))
(setq p3 (polar p2 (+ alf pi) (* 0.7 d)))
(setq p4 (polar p3 (+ alf (* -0.5 pi)) (* 0.5 d)))
(setq p5 (polar p4 (+ alf (* -0.5 pi)) d))
(setq p6 (polar p5 (+ alf (* -0.5 pi)) (* 0.5 d)))
(setq p7 (polar p6 alf (* 0.7 d)))
(setq p8 (polar p7 (+ alf (* 0.5 pi)) (* 0.5 d)))
(command "line" p2 p3 p6 p7 "c")
(command "line" p1 p4 "")

(command "line" p5 p8 "")


(drawwhorl s_t p0 d l alf cen_md cc tc sc)
))

(if (= s_t "3"); GB/T 70.1-2000


(progn
(setq p1 (polar p0 (+ alf (* 0.5 pi)) (* 0.75 d)))

(setq p2 (polar p1 (+ alf pi) d))


(setq p3 (polar p2 (+ alf (* -0.5 pi)) (* 0.2925 d)))
(setq p4 (polar p3 alf (* 0.5 d)))
(setq p5 (polar p4 (+ alf (* -0.5 pi)) (* 0.22875 d)))
(setq p6 (polar p5 (+ alf pi) (* 0.5 d)))

(setq p7 (polar p6 (+ alf (* -0.5 pi)) (* 0.4575 d)))


(setq p8 (polar p7 alf (* 0.5 d)))
(setq p9 (polar p8 (+ alf (* -0.5 pi)) (* 0.22875 d)))
(setq p10 (polar p9 (+ alf pi) (* 0.5 d)))
(setq p11 (polar p10 (+ alf (* -0.5 pi)) (* 0.2925 d)))

(setq p12 (polar p11 alf d))


(command "line" p1 p2 p11 p12 "c")
(command "linetype" "s" "dashed" "")
(command "line" p3 p4 p9 p10 "")
(command "line" p5 p6 "")

(command "line" p7 p8 "")


(command "linetype" "s" "bylayer" "")

(drawwhorl s_t p0 d l alf cen_md cc tc sc)


)
)
)

(defun drawwhorl (s_t p0 d l alf cen_md cc tc sc)


(setq p1 (polar p0 (+ alf (* 0.5 pi)) (* 0.425 d)))
(setq p2 (polar p0 (+ alf (* 0.5 pi)) (* 0.5 d)))
(setq p3 (polar p2 alf l))
(setq p4 (polar p1 alf l))
(setq p8 (polar p0 (+ alf (* -0.5 pi)) (* 0.425 d)))
(setq p7 (polar p0 (+ alf (* -0.5 pi)) (* 0.5 d)))
(setq p5 (polar p8 alf l))
(setq p6 (polar p7 alf l))

(command "line" p2 p3 p6 p7 "c")

(if (> l (* 2 d));


(progn
(setq p9 (polar p3 (+ alf pi) (* 2 d)))

(setq p1 (polar p4 (+ alf pi) (* 2 d)))


(setq p8 (polar p5 (+ alf pi) (* 2 d)))
(setq p10 (polar p6 (+ alf pi) (* 2 d)))

(command "line" p9 p10 "");


)
)
(command "color" tc)
(command "line" p1 p4 "");
(command "line" p5 p8 "")

(if (= cen_md "1");


(progn;
(setq dl(cond ((= s_t "0") (* 1.1 d))
((= s_t "1") d)
((= s_t "2") (* 1.2 d))
((= s_t "3") (* 1.5 d))

))
(command "color" cc)
(command "linetype" "s" "center" "")
(setq pr (polar p0 (+ alf pi) dl))
(setq pl (polar p0 alf (+ l (* 0.5 d))))
(command "line" pl pr "")
(command "linetype" "s" "bylayer" "")
)))

13.2

1
2
3

CAD

13.2.1

1
13-3a

13-3

2
3subtract

4
rr13-3b
24360
13-3c


CAD

region3

13.2.1

entlast
entlast

2
13-4
p0p1
p2 pline region
circleregion

13-4

3
subtruct
copy

4
moveXdxrotate
ddx = rdr
dx

13.2.3

1.
4
13-2.dcl13-5
13-5
d:example\dcl\

13-2.lspAutoLISP
d:example\ lisp\
13-2-1.sld13-2-2.sld
d:example\sld\

4.
13-2.lspCommandmgear13-5
OK

13-5

13-6

13-6

13.2.4
13-213-513-6
//13-5

mgear:dialog{//mgear
label="";
:row{//
:image{width=35;//
height=12;

key="image";
color= -2;
}
:column{//5
:row{//1

:popup_list{label="&m";
key="_m";
value="5";
}
:popup_list{label="&a";
key="_alf";

value="2";
}
}

:row{//2
:edit_box{label="&Z";
key="_z";

edit_width=6;
value="20";
}

:slider{
key="s_z";
min_value=8;

max_value=100;
small_increment=1;
}
}
:row{//3

:edit_box{label="&x:";
key="_x";
edit_width=3;
value="0";
}

:slider{ key="s_x";
min_value=-100;
max_value=100;

small_increment=1;
value=0;
}
}
:boxed_radio_row{//4

label="";
:radio_button{label="";key="prec0";}
:radio_button{label="";key="prec1";}
:radio_button{label="";key="prec2";value=1;}
}

}//
}//
ok_cancel;

}
//13-6

gear_list:dialog{// gear_list
label="";
:row{//1
:image{width=35;//
height=12;
key="image2";

color= -2;
}

:column{//7
:text{value="m: ";key="t1";}
:text{label="z: ";key="t2";}

:text{label="a: ";key="t3";}
:text{label="x:";key="t4";}
:text{label="d: ";key="t5";}
:text{label="da: ";key="t6";}
:text{label="di: ";key="t7";}

}
}
:row{//222

spacer_1;

spacer_1;
:button{label="";
key="accept";

is_default=true;
fixed_width=true;
}
:button{label="";
key="xwj";

fixed_width=true;
}
spacer_1;
}
}

13.2.5
1.
1dlg1
2getd
3fz

4fsz
5f_x
6fs_x
7makegear
8showdata
9fwfile
10mgearmgearAutoCAD

2.
msh msh_yljylj_chsh
chgaochdgaoxshchdjxbwxsh
chwchlzhxfdybjdybj
kbjjybjchtgen
lm1lm2qxcsh
dxdphi

3.
13-2
(defun dlg1();

(set_tile "_m" "5");6


(set_tile "_z" "20");20
(set_tile "_alf" "2");3

(set_tile "s_z" "20");


(set_tile "cut" "2");3

(action_tile "_m"

"(setq msh_ $value)")

(action_tile "s_z"
(action_tile "_z"

"(fsz)")
"(fz)")

(action_tile "s_x"
(action_tile "_x"

"(fs_x)")
"(f_x)")

(action_tile "_alf"

"(setq ylj_ $value)")

(action_tile "prec0"

"(setq qxcsh 5)")

(action_tile "prec1"

"(setq qxcsh 10)")

(action_tile "prec2"

"(setq qxcsh 15)")

(action_tile "accept"

"(getd)(done_dialog

(action_tile "cancel"

"(done_dialog

(action_tile "help" "(dlg3)")


)

0)")

1)")

(defun getd()
(setq msh_ (get_tile "_m"))
(setq msh (atof(nth (atoi msh_) m_lst)));

(setq ylj_ (get_tile "_alf"))


(setq ylj (atof(nth (atoi ylj_) alf_lst)));
(setq bwxsh(atof(get_tile "_x")));
(setq chsh(atoi(get_tile "_z")));
)

(defun fz(/

gz)

(setq gz(atoi $value))


(if (or (< gz 9)(> gz 100))
(progn
(set_tile $key (get_tile "s_z"))

(setq chsh(atoi $value))


)
(progn

(set_tile "s_z" (itoa gz))


(setq chsh gz)
)
)
)

;
(defun fsz()
(set_tile "_z" $value)

(setq chsh (atoi $value))


)
;
(defun fs_x(/ xx)
(setq xx (atof $value))
(setq bwxsh(* 0.01 xx))
(setq xx(rtos bwxsh 2 2))

(set_tile "_x" xx)


)

(defun f_x(/

xx )

(setq xx(atof $value))


(if (or (< xx -1)(> xx 1))
(progn
(setq xx (get_tile "s_x"))
(setq xx(atof xx))
(setq bwxsh(* 0.01 xx))
(set_tile $key (rtos bwxsh 2 2))

)
(progn
(setq bwxsh xx)

(setq xx(* 100 xx))


(set_tile "s_x" (itoa xx))
)))

;
(defun makegear()
(setq chlzhx '(0 0));

(setq ylj (* pi (/ ylj 180.0)));


(setq chgao (* msh (+ chdgaoxsh bwxsh)));=1
(setq fdybj (* 0.5 (* msh chsh)));
(setq dybj (+ fdybj (* msh (+ chdgaoxsh bwxsh))));
(setq kbj (* 0.25 dybj));

(setq lm1 (list (- (car chlzhx) (* 2 dybj)) (+ (last chlzhx)


dybj)));
(setq lm2 (list (+ (* 5 msh) (car chlzhx) dybj) (- (last chlzhx)
(+ 10.0 (* chdjx msh)) dybj)));
(command "zoom" lm1 lm2)

(setq jybj (+ fdybj (* bwxsh msh)));=+


(setq temy1 (* msh (+ chdjx chdgaoxsh)));1+0.25
(setq chtgen (+ jybj temy1));

(setq chtdi (+ chtgen 3.0));


(setq chtdi (- (cadr chlzhx) chtdi));y
(setq chtzuo (- (car chlzhx) (* 2 jybj)));x
(setq p01 (list chtzuo chtdi))
(setq chw (* pi msh));

(setq chtgeny(+ chtdi 3.0));y


(setq p0 (list chtzuo chtgeny))
(setq chh (* 2.0 temy1));
(setq chb (/ (* chh (sin ylj)) (cos ylj)))
(setq cha (* 0.25 (- chw (* 2 chb))))

(setq chnu(* 0.5 chsh));


(setq chnum 0.0)
(command "color" "white")
(setq chtemp p0)
(command "pline" p01 p0 )
(while(< chnum chnu);

(setq chnum (1+ chnum))


(command (setq p1 (list (+ cha (car p0)) (cadr p0))))
(command (setq p2 (list (+ chb (car p1)) (+ chh (cadr p1)))))
(command (setq p3 (list (+ (* 2.0 cha) (car p2)) (cadr p2))))
(command (setq p4 (list (+ chb (car p3)) (- (cadr p3) chh))))
(command (setq p5 (list (+ cha (car p4)) (cadr p4))))
(setq p0 p5)
)

(setq p02 (list (+ chtzuo (* chnum chw)) chtdi))


(command p02 p01 "c");
(setq e1(entlast));
(command "region" e1 "");
(setq tiao(entlast));

(command "color" "white")


(command "circle" chlzhx dybj);

(setq c1(entlast));
(command "region" c1 "");
(setq c1(entlast));
(command "circle" chlzhx kbj);

(setq c2(entlast));
(command "region" c2 "");
(setq c2(entlast));
(command "subtract" c1 "" c2 "");
(setq lun(entlast));

(setq dphi(/ 360.0 (* chsh qxcsh)));


(setq chtydjl (/ chw qxcsh));
(setq shjqxcsh 0);
(setq ydjl 0.0);
(while (<= shjqxcsh (* qxcsh chsh))

(setq ydjl (+ ydjl chtydjl))


(setq dx chtydjl);

(if (>= ydjl chw)


(progn;ydjlchw
(setq ydjl 0.0)
(setq dx (* (- 1 qxcsh) chtydjl));
)
)

(command "copy" tiao "" '(0 0) '(0 0));


(setq tiao1(entlast))
(command "subtract" lun "" tiao1 "");

(command "rotate" lun "" chlzhx dphi);dphi


(command "move" tiao "" '(0.0 0.0) (list dx 0.0));dx
(setq shjqxcsh (1+ shjqxcsh))
)
)

;
(defun showdata()
(if (not (new_dialog "gear_list" id))(exit))

(setq x1(dimx_tile "image2")) ;x1


(setq y1(dimy_tile "image2"))

;y1

(start_image "image2") ;
(slide_image -10 -10 (+ x1 20) y1 "d:/example/sld/13-2-2")
(end_image) ;
(set_tile "t1" (strcat "m: " (rtos msh 2 2)))
(set_tile "t2" (strcat "z: " (itoa chsh)))

(setq ylj(* 180 (/ ylj pi)))


(set_tile "t3" (strcat "a: " (rtos ylj 2 2) "" ));jlj0

(set_tile "t4" (strcat "x: " (rtos bwxsh 2 2)))


(set_tile "t5" (strcat "d: " (rtos (* 2 fdybj) 2 2)))

(set_tile "t6" (strcat "da: " (rtos (* 2 dybj) 2 2)))


(set_tile "t7" (strcat " df: " (rtos (* 2 (- dybj (*
2.25 msh))) 2 2)))
(action_tile "accept"

"(done_dialog

(action_tile "xwj" "(done_dialog


(if (> (start_dialog) 1)(fwfile))
)

1)")

2)")

;
(defun fwfile()
(setq fname(getfiled "" "" "txt" 1))

(setq fp(open fname "w"))


(write-line (strcat "m: " (rtos msh 2 2)) fp)
(write-line (strcat "z: " (itoa chsh))fp)
(write-line (strcat "a: " (rtos ylj 2 2) "" )fp)
(write-line (strcat "x: " (rtos bwxsh 2 2))fp)
(write-line (strcat "d: " (rtos (* 2 fdybj) 2 2))fp)
(write-line (strcat "da: " (rtos (* 2 dybj) 2 2))fp);
(write-line (strcat "df: " (rtos (* 2 (- dybj (* 2.25 msh)))
2 2))fp)
(close fp)
)

;
(defun c:mgear( / bwxsh c1 c2 cha chb chdgaoxsh chdjx chgao chh
chnu chnum
chsh chlzhx chtdi chtemp chtgen chtgeny chtydjl
chtzuo chw dphi dx dybj e1 fdybj fname fp jybj kbj lm1 lm2 lun
msh msh_ p0 p01 p02 p1 p2 p3 p4 p5 qxcsh shjqxcsh temy1 tiao
tiao1 x0 x1 y0 y1 ydjl ylj ylj_ zhxx zhxy)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setvar "osmode" 0)
(setq chdgaoxsh 1.0);

(setq chdjx 0.25);


(setq qxcsh 15)
(setq id(load_dialog "d:/example/dcl/13-2")) ;

(if (< id 0)(exit))


(setq what 3)

(while (> what 1)


(if (not (new_dialog "mgear" id))(exit))
(setq x1(dimx_tile "image1")) ;x1

(setq y1(dimy_tile "image1")) ;y1


(start_image "image1")

(slide_image -10 -25 (+ x1 20) y1 "d:/example/sld/13-2-1")


(end_image) ;
(setq m_lst(list "1" "1.25" "1.5" "2" "2.5" "3"
"8" "10"))
(start_list "_m") ;
(mapcar 'add_list m_lst)

(end_list);
(setq alf_lst(list "14.5" "15" "20" "22.5" "25"))

"4" "5" "6"

(start_list "_alf");
(mapcar 'add_list alf_lst)
(end_list);
(dlg1)

(if (/= what 2) (setq what (start_dialog)))


)

;while

(if (= what 1)
(progn
(makegear);
(showdata);
)
)
(unload_dialog id);
)