高级语言与AutoCAD的数据传送
程序1的例子是一个BASIC程序,由用户告知所画的图形是折线(以“L”表示)还是圆(以“C”表示),然后将有关数据组织成顺序文件(如程序2所示),再利用程序3的AtuoLISP程序画出折线或圆。
程序1 BASIC程序
10 CLS
20 OPEN"cad.dat"FOR OUT PUTAS#1
30 READM$,A1,A2,A3,A4,A5,A6
40 IF M$="END"THEN70
50 PRINT#1,"((m";CHR$(34);M$,CHR$(34),")(p1(";A1;"";A2;"))(p2("A3;"";A4;))(p3(";A5;"";A6;")))"
60 GOTO 30
70 CLOSE#1
80 END
90 DATA L,1,2,3,4,5,1
100 DATA c,1,2,3,4,5,1
110 DATA END
程序2顺序文件内容
((m"l")(p1(12))(p2(34))(p3(51)))((m"c")(p1(12))(p2(34))(p3(51)))
程序3AutoLisp程序
(defun draw()
(setqf(open"cad.dat""r")
(setq data(read-linef))
(while(/=datanil)
(setqp(readdata))
(cond((=(cadr(assoc'mp))"l")
command"line"(cadr(assoc'plp))
(cadr(assoc'p2p))(cadr(assoc'p3
p))'0))
((=cadr(assoc'mp))"c")
(command"circle""3p"
(cadr(assoc'plp))(cadr
(assoc'p2p))(cadr(assoc'p3p))))
)
(setq data(read-linef))
)
(setq f(closef)