Professional Documents
Culture Documents
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
Visual LISPMicrosoft
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
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
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
252525
quote
3 2 1psetq p3 2 1
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
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
p4
p3
p1
p2
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
((<= 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
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)
)
)
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
Command:
(chicken)
("=" 2 " =" 30 " =" 68)
("=" 5 " =" 25 " =" 70)
3.2 AutoLISP
3.2.1 AutoLISP
AutoLISP.lspAutoLISP
LISPAutoCAD
(defun plus(x y)
(+ (* x y) x)
)
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)
)
)
Visual LISP
3.3.2
(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)
asas ASCII
while
3.2.3 AutoCADAutoLISP
1
AutoLISPloadload
Command(load
":\\\\"
["
"])
lisp
fi1e1.lspfunc1
d:\user1
Command(load
" )
"
func1"
"
Command(load
"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
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
2. Visual LISP
Visual LISPFileExit
AutoCADVisual
LISPVisual LISP
Visual LISPVisual LISP
3. AutoCAD
Windows
Visual LISPWindowActivate AutoCAD
View
AutoCAD
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
4.4
1.
FileNew FileCtrl+N
2.
FileOpen FileCtrl+O
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
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
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
5-7
1Right Text Margin
20~200
2Narror style indentation
1~6
3Maximum wide-style car length
6Insert tabs
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
5.4
1.
AutoLISP
5-9
5-9
5-5
5-5
Ctrl+]
Ctrl+[
Ctrl+Shift+]
Ctrl+Shift+[
(setq alf1(cond
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
90) (<=
alf
270)) (-
alf 180))
Ctrl+Shift+[ cond
co
2.
AutoLISP
3.
1Visual LISP
2
ToolsCheck Text in Editor
ToolsCheck Selection
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
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."
6-6P1P2P3P4
1DebugAdd Watch
p1
OKP2P3P4
100.0]P4XX(car pl)
(car pl)carpl
PL = nilPL
p1
3plp1
6.3
6-1
p3
p4
w (getdist p1 "")
h (getdist p1 ": ")
alf (getangle p1 ": ")
)
alf
p1
p2
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
AutoCAD
5 (getangl
p1 "
: ")"
: ""; error: no function definition:
GETANGLGETANGL"
2.
1
6-1wh
alfp1p2p3p4DebugAnimate
AutoCAD"Command""rect3"Visua
lLISP
"I"""
"
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
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
3.
6-2 6-10p0dbt1alf
6-10
(setq d
(setq b
(setq tl
;tanatan
FileOpen File6-2
DebugAdd Watch
p0dbt1alfrlb1sitp1p2p3p4p5
AutoCADCommand:
Command:TUXING
p0dbt1alf
15get
p0 d b alf
Command:TUXING
p01
t1
"; error: no
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
(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
(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
(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
: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))
)
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
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
6-28
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
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"
Visual LISP".lsp"
3.
".fas"
AutoCAD"d:\autocad2006\"
(vlisp-compile 'st "sample.lsp" " sample.fas")sample.fas
"d:\autocad2006\"
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 "
lisp file"
2Visual LISP
LISPAutoCAD"C"
AutoCAD
LISPAutoCADAutoCAD
3 AutoLISP
(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
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
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
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
7-13
file1.lsp
r-hexagonAutoCADfile2.lsp
hexagonhexagond
user1
file1.lsp
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)
)
(if (>= l lmin)
(progn
(setq l(/ l (+ (cos alf) (* (sin alf) 0.5773503))));
)
))
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
3. Link mode
3
l Do Not Link:
l Link:
l Internal:
AutoCAD
4. Message mode
3
Fatal errors
5. Localize variables
Optimize
6. Safe optimize
Optimize
7. Fas directory.fas
.fas
8. Tmp directory
8.1
AutoCAD
command
setvar
1.
420,297
A3
1command
0,0
(command "limits"
'(0
0)
(command "limits"
(list 0
'(420 297))
0)
p1p2
2setvar
limminlimmax
setvar
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
EXTension
PARallel
1command
(command "osnap" "endpoint,midpoint,center")
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
"L" "Center"
ColorLtype
2.
1command
(command "color" 3)
(command "color" "green")
2setvar
(setvar "cecolor" "2")
3.
1command
(command "linetype" "s" "centerset" "")
2setvar
(setvar "celtype" "dashed")
4.
continuous
1command
(command "ltscale" 0.5)
2setvar
(setvar "ltscale" 0.5)
5.
1command
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
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 "layer"
""))
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" "" "" "" ""
"")
3big font
Windows
AutoCADc
%%d%%p
8-2A4
GB/T 14689-1993GB/T10609-1989
1. A4
(defun c:a4( /
a4
(command "style" "hz" "gbcbig" "" "" "" "" "" "")
hz
(command "layer" "m" "xixian" "c" "1" """")
xixian
(command "limits" "0,0" "210,297")
0.6
2.
12-4getvarosmode
v1v2v3
25-7setvarosmode
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
"h""v"
(setq p1 '(10 10) p2 '(40 25) p3 '(45 25))
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.
3.
""
(command "dimdiameter" p1 p2)
(command "dimdiameter" p1 "105,105")
(command "dimdiameter" p1 "@-7.5,5")
p1p2
"105,105"
"@-7.5,5"p1XY
""
"R"
4.
""
45
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"
"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" "" "")
AutoCADcopy3
copycommand
w
-5,-5
5,5
""
m
0,0
12,024,036,0
""
8-4 4
4
(command "fillet" "r" 1.5)
"p"4
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
bhatch
ppick
ansi31
1.5
0
0,0
""
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)
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)
(* 0.25
p2 (polar p0
p4 (polar p0
p6 (polar p0
p10
pr
(polar p0
)
(setq p13 p1 p14
p2) 2
)
(command "lweight" 0)
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
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"))
(setvar "cmdecho" 0)
(setq p0(getpoint ": "))
(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
)
360
(t alf)
)
)
(setvar "blipmode" 0) ;
(if (= s "0")
(progn
(progn ;
(command "line" p2 p3 p0 p1 "")
(if (> (strlen s) 3) 3p4
)
)
(setvar "cmdecho" v1)
(setvar "blipmode" v2)
(princ)
)
8-9a
bp0alf
AutoCAD
pi) b))p1p8
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\
(setq f1(open "d:\\example\\dat\\8-10.dat" "r"))
f1
2
(close )
(close f1)
3
(read-line)
4
(read )
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)
(command "dimlinear"
18,0");d2
p2
(command "dimlinear"
"@12,0");d3
p9
p5
"ver"
p6
"t"
"ver"
"%%c<>"
"t"
"@-
"%%c<>"
(close f1);
8-10.dat
9.1
AutoCAD
16
entnext
entlast
entnext
(setq e1(entnext))
<Entity name: 7ef6ce88>e1
9-14
1
e1
e2e3e4
(setq e4(entlast))
AutoCADcopy3
[9-2] bp0d
bh
AutoCAD
(defun c:keyway()
(setq pc (getpoint " "))
(setq d (getdist pc ""))
(setq b (getdist pc ""))
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
(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)
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
6
(entmod elist)
entmod
5.03.5
9.2.3
9-3
e1
e1
e1nil
TEXTMTEXT
MTEXT
MTEXT
e1"TEXT"
e1
e1e1
(setq e(entnext))
(while e e
(setq el(entget e))
(if (= "TEXT" (cdr (assoc 0 el)))
(progn "TEXT"
(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
0) '(10
10)))
(0,0)(10,10)
s2
(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
(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"
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
0) (62 . 7) (6 . "CONTINUOUS"))
new_cl
el
(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)) ;
(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
; 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)
; 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>
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
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)
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
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.2vlax-dump-object
AutoCAD
Addline
AutoCAD
107
Addline108
108
Visual LISP
Visual BasicVisual BasicAddLine
Visual LISP
1Visual BasicAutoLISP
2AutoLISPActiveX
AutoLISP
(setq myline(vla-addline myms (vlax-3d-point '(10 20)) (vlax-3dpoint '(80 30))))
myms
object .
AddLine
(StartPoint,
EndPoint)
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
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
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
10-5
10-5
vlax-false
nil
(vlax-vbEmpty)
vlax-safearray-fill
(vlax-safearray-fill
')
#<safearray...>
p10
2vlax-safearray-fill
vlax-safearray-fill
(vlax-safearray-fill p1 '(1 2 3 4)) error: vlaxsafearray-fill failed. Invalid initialization list.
mt2
01
13vlax-safearray-fill
3
vlax-safearray->list
(vlax-safearray->list )
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"
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 ...>
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
2. VLAAutoCAD
vlax-vla-object->ename VLA
AutoCAD
(vlax-vla-object->ename VLA)
AutoCAD
vla-objectVLA
VLAAutoCAD
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 area(vla-get-area
circ))7853.98
(setq area(vla-get-color
circ))256(bylayer)
2. vlax-get-propertyActiveX
vlax-get-property
(vlax-get-property VLA property)
property
(setq
cntr
(vlax-get-property
circ
8197 ...>,
'center)) #<variant
10.4.2
(100 80)50
VLAcirc
1. vla-put-
(vla-put-property VLA )
vla-put- property
propertyVLA
property
radius20
(vla-put-area
1000
circ 1000)nil,
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 'center (vlax-3d-point '(180
20 0))); nil, (180 20 0)
acRed1
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
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
method
VLATnil
copymyline
AddBoxmyline
2.
vlax-property-available-p
(vlax-property-available-p VLA
modify)
property [check-
propertycheckmodifyTVLAVLA
TnilcheckmodifyTnil
ColorCentermyline
(vlax-property-available-p myline "Color")T
TArea
10.8
AutoCADAutoCAD
AutoCADVLISP
vlax-map-collectionvlax-for
10.8.1 14
vlax-map-collection
(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)
; Area = 7853.98
; 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
colorSublist
(vla-get-ActiveDocument
objectColor
(1+(cdr
colorSublist)))
(if colorList
(progn
(setq colorList (vl-sort colorList '(lambda
(car lst1) (car lst2)))))
(princ "\nColorList = ")
(princ colorList)
(foreach subList colorList
(princ "\nColor ")
"s.")))))
(princ)
)
124
6
(show-Color-Statistics)
10.8.3
itemcount
itemcount
1.
vla-get-count
(vla-get-count myms)
vla-item
2.
(vla-get-count myms)
(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
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 " ")
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
(vlax-get-acad-
'vla-getboundingbox
(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));
2. ActiveX
ActiveX
VLA
10-5ActiveX
(alert "0")
(setq area(getreal "\n:"));
)
(setq v_c(vlax-ename->vla-object ec));
VLA
11
11.1
1.
AutoCAD
lAutoCAD
DXF
l ARX
lAutoCAD
vlr-types11-1
AutoCAD
11-1AutoCAD
:VLR-AcDb-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-
(vlr-reaction-names :vlr-object-reactor)
;(:VLR-cancelled :VLR-copied :VLR-erased :VLR-unerased :VLRgoodbye :VLR-openedForModify :VLR-modified :VLR-
(defun print-reactors-and-events ()
)
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
(vl-load-com)
(cond
((vlax-property-available-p notifier-object "Radius")
radius
(princ ")
11.2.2
AutoCAD
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
)
(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
(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-Object-Reactor>))
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
11.4.2
1
vlr-reaction-set
reactor event
FunctionAutoLISP
circleReactor
print-area
2.
vlr-data-set
3.
vlr-owner-add
circleReactor {Owners}
113
113
4.
vlr-owner-remove
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
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
5.
AutoCAD
VLX
VLISP
AutoCADvlrpers-list
11.6
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
nil '((:vlr-modified .
(princ)
)
;
Commandrct-line
114
114
2. 115
115
11-4:vlr-modified
11-5
(vl-load-com)
(princ);
)
;c-2l
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))));
(entmod ell_1);
(setq ell_2(entget el2));
(setq ell_2(subst (vl-list* 10 p2)(assoc 10 ell_2)ell_2));
(entmod ell_2);
)
Commandc1l2
115
VLA
AutoLISP
ActiveX
145ActiveX144
(vl-load-com)
(princ)
)
;c-2l
12
12.1
1.
2.
12-1
12-1
3.
12-1DCL
VLISP
ToolsInterface ToolPreview DCL in Editor12-2
sample:dialog {
label = "";
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
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
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;
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";}
}
key= "a3";
value=1;}
12-12
boxed_radio_columnalignment
children_alignment
children_fixed_height
":boxed_radio_column{label="
""
12-13
12-13
5. Row
12-14
key="dir"; }
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
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";}
}
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=""; }
}
}
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"))
(princ)
)
5. ok_cancel_help_errtile
OKCancelHelp3
4errtile
AutoLISPset_tilevalue
//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))
(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
nameitem1name:item
nameitemattribute1item
value1"{ attribute1=value1;}"item1
value1attribute1itemattribute1
attribute1name"{ }"
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
(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_function1
usrt_function
action
4.
(1) (mode_tile
key
mode)
keymode
0
34
key
attribute
keyattribute
(setq w(get_attr
w
(3)get_tile key
keyvalue
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
(end_image);
12-18
7.
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
""""
"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
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
2.
1
OK
key"accept"
done_dialog
(action_tile
getdata
1done_dialog
2cancel key
"cancel"done_dialog
(action_tile
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
xc 50.0 yc 50 r 25);
(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
(slide_image 0 0 x1 y1 "d:\\example\\sld\\12-13");
12-13.sld
(end_image) ;
(initget 1)
(setq p(getpoint ":"))p
(setq x (car p) y (cadr p))pXYxy
)
)
)while
(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
(defun dlg2();zxjdian
(if (not (new_dialog "zxjdian" id))(exit))
(initimg
"rect2"
"d:/example/sld/12-14-2");
12-14-2.sld
(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
(progn
(initget 1);
(setq p(getpoint "\n:"))
(list x (+ y w))
"c")
)
(unload_dialog id);
(princ);
)
: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);
(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
(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)
//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
(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
(setq sdt(start_dialog))
(unload_dialog id)
(if (> sdt 0) (princ (list " =" len
area)))
(princ)
)
;ll
(progn
;ll
(set_tile "sld_l"
(itoa ll))
)
)
)
(defun fsldl();
(set_tile "edit_l" $value) ;
;ww
)
)
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 = ""; //
: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))
;
(defun initdlg1 ()
(if(not (new_dialog "main_dlg" id))(exit))
"user_dim"
"(f_user
(get_tile
\"user_dim\"))
(getdata)");
(action_tile "accept" "(getdata)(done_dialog 1)");
OK
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
(= 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"));
(if (= sdt 4)
(progn;
(if (= sdt 4)
(progn;
(initget 1);
(setq ang (getangle p0 ": "))
(setq alf (* 180.0 (/ ang pi)))
)));while
(unload_dialog id);
(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)
))
(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();
(action_tile "_m"
(action_tile "s_z"
(action_tile "_z"
"(fsz)")
"(fz)")
(action_tile "s_x"
(action_tile "_x"
"(fs_x)")
"(f_x)")
(action_tile "_alf"
(action_tile "prec0"
(action_tile "prec1"
(action_tile "prec2"
(action_tile "accept"
"(getd)(done_dialog
(action_tile "cancel"
"(done_dialog
0)")
1)")
(defun getd()
(setq msh_ (get_tile "_m"))
(setq msh (atof(nth (atoi msh_) m_lst)));
(defun fz(/
gz)
;
(defun fsz()
(set_tile "_z" $value)
(defun f_x(/
xx )
)
(progn
(setq bwxsh xx)
;
(defun makegear()
(setq chlzhx '(0 0));
(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));
;
(defun showdata()
(if (not (new_dialog "gear_list" id))(exit))
;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)))
"(done_dialog
1)")
2)")
;
(defun fwfile()
(setq fname(getfiled "" "" "txt" 1))
;
(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);
(end_list);
(setq alf_lst(list "14.5" "15" "20" "22.5" "25"))
(start_list "_alf");
(mapcar 'add_list alf_lst)
(end_list);
(dlg1)
;while
(if (= what 1)
(progn
(makegear);
(showdata);
)
)
(unload_dialog id);
)