[LISP]计算单行文字+、-、*、/的程序
<P> 本人前几天找到一个计算单行文字的用LISP语言编的可实现+、-、*、/的程序,加载后从命令行输入JS就行了,共享一下,代码如下:</P><P>(defun *error* (ERROR)<BR> (princ "error:")<BR> (princ "CAO ZUO ERROE")<BR> (PRINC "\n please try a time")<BR> )<BR>(defun getss(/ SS N I NAME0 NAME X0 X1)<BR> (INITGET (+ 1 2 4))<BR> (setq ss (ssget '((0 . "TEXT"))))<BR> (if (= ss nil) (setq ss (ssadd)))<BR> (setq ssa (ssadd))<BR> (while (/= (setq n (sslength ss)) 0)<BR> (progn<BR> (setq i 1)<BR> (setq name0 (ssname ss 0))<BR> (setq x0 (caddr (assoc 10 (entget name0))))<BR> (while (< i n)<BR> (progn<BR> (setq name (ssname ss i))<BR> (setq X1 (caddr (assoc 10 (entget name))))<BR> (if (< X0 X1) <BR> (progn<BR> (setq name0 name)<BR> (setq X0 X1)<BR> ))<BR> (setq i (+ 1 i))<BR> ))<BR> (setq ssa (ssadd name0 ssa)) <BR> (setq ss (ssdel name0 ss))<BR> ))<BR> )</P>
<P>(DEFUN C:JS(/ NN II ENT NAME TXT PP P0 PP0 NAME1<BR> P ST ZH ZW ANG I N W TEMP)<BR> (SETvar "BLIPMODE" 0)<BR> (SETvar "CMDECHO" 0)<BR> (PROMPT "\n FIRST-SSGET:")<BR> (INITGET (+ 1 2 4))<BR> (getss)<BR> (SETQ SS1 ssa)<BR> (PROMPT "\n SECOND-SSGET:")<BR> (getss)<BR> (SETQ SS2 ssa)<BR> <BR> (INITGET (+ 1 2 4))<BR> (IF (= (SSLENGTH SS2) 0) <BR> (SETQ JSF (GETSTRING "\n JI SUAN FU:?<+> "))<BR> (SETQ JSF (GETSTRING "\n JI SUAN FU:?<*> ")))<BR> (WHILE (AND (/= JSF "+") (/= JSF "-") (/= JSF "*") (/= JSF "/") (/= JSF ""))<BR> (GETSTRING "\n JI SUAN FU:?<*> "))<BR> (IF (AND (= (SSLENGTH SS2) 0) (= JSF "")) (SETQ JSF "+")) <BR> (IF (AND (/= (SSLENGTH SS2) 0) (= JSF "")) (SETQ JSF "*"))<BR> <BR> (SETQ P0 (CDR (ASSOC 10 (ENTGET (SSNAME SS1 0)))))<BR> (INITGET (+ 1 2 4))<BR> (SETQ PP0 (GETPOINT "\n TEXT-POINT:?"))<BR> (SETvar "BLIPMODE" 0)<BR> (IF (= (SSLENGTH SS2) 0) <BR> (PROGN<BR> (SETQ XI (GETREAL "\n XU CHU DE XI SHU [/] :?<1>")) <BR> (IF (= XI NIL) (SETQ XI 1)))<BR> (PROGN<BR> (SETQ XI (GETREAL "\n XU CHU DE XI SHU [/]:? <100>")) <BR> (IF (= XI NIL) (SETQ XI 100))<BR> ))</P>
<P> (SETQ WS (GETINT "\n XIAO SHU WEI:?<2> "))<BR> (IF (= WS NIL) (SETQ WS 2))<BR> (SETQ NN1 (SSLENGTH SS1))<BR> (SETQ II 0)<BR> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR> (IF (= (SSLENGTH SS2) 0)(PROGN<BR> (WHILE (< II NN1)<BR> (SETQ ENT1 (ENTGET (SETQ NAME1 (SSNAME SS1 II))))<BR> (IF (= II 0) (SETQ NAME0 NAME1))<BR> (SETQ TXT1 (CDR (ASSOC 1 ENT1)))<BR> (SETQ TXT1 (ATOF TXT1))<BR> (IF (= II 0) (SETQ TXT TXT1)) <BR> (IF (/= II 0) (PROGN<BR> (COND ((= JSF "+") (SETQ TXT (+ TXT TXT1)))<BR> ((= JSF "-") (SETQ TXT (- TXT TXT1)))<BR> ((= JSF "*") (SETQ TXT (* TXT TXT1))) <BR> ((= JSF "/") (SETQ TXT (/ TXT TXT1)))<BR> )<BR> ))<BR> (SETQ II (+ II 1))<BR> )<BR> (COMMAND "COPY" NAME0 "" P0 PP0)<BR> (SETQ TXT (/ TXT XI))<BR> (SETQ TXT (RTOS TXT 2 WS))<BR> (setq txt-style (cdr (assoc 7 (entget name0))))<BR> (setq style-higth (cdr (assoc 40 (tblsearch "style" txt-style))))<BR> (if (= style-higth 0.0)<BR> (COMMAND "CHANGE" "L" "" "" "" "" "" "" TXT )<BR> (command "change" "l" "" "" "" "" "" txt))<BR> ))<BR> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR> (IF (AND (/= SS2 NIL) (/= SS1 NIL)) (PROGN<BR> (SETQ NN2 (SSLENGTH SS2))<BR> (IF (>= NN1 NN2) (SETQ NN NN2) (SETQ NN NN1))<BR> (WHILE (< II NN)<BR> (SETQ ENT1 (ENTGET (SETQ NAME1 (SSNAME SS1 II))))<BR> (SETQ ENT2 (ENTGET (SETQ NAME2 (SSNAME SS2 II))))<BR> (SETQ TXT1 (CDR (ASSOC 1 ENT1)))<BR> (SETQ TXT2 (CDR (ASSOC 1 ENT2)))<BR> (SETQ TXT1 (ATOF TXT1))<BR> (SETQ TXT2 (ATOF TXT2))<BR> (COND ((= JSF "+") (SETQ TXT (+ TXT1 TXT2)))<BR> ((= JSF "-") (SETQ TXT (- TXT1 TXT2)))<BR> ((= JSF "*") (SETQ TXT (* TXT1 TXT2))) <BR> ((= JSF "/") (SETQ TXT (/ TXT1 TXT2)))<BR> )<BR> (COMMAND "COPY" NAME1 "" P0 PP0)<BR> (SETQ TXT (/ TXT XI))<BR> (SETQ TXT (RTOS TXT 2 WS))<BR> (setq txt-style (cdr (assoc 7 (entget name1))))<BR> (setq style-higth (cdr (assoc 40 (tblsearch "style" txt-style))))<BR> (if (= style-higth 0.0)<BR> (COMMAND "CHANGE" "L" "" "" "" "" "" "" TXT )<BR> (command "change" "l" "" "" "" "" "" txt))<BR> (SETQ II (+ II 1))<BR> )<BR> ))<BR> (SETvar "BLIPMODE" 0)<BR> (SETvar "CMDECHO" 0)<BR> (PRINC)<BR> )<BR>(DEFUN C:TCH(/ SS NN II ENT NAME TXT PP0 P0 P XI JSF WS)<BR> (SETvar "BLIPMODE" 0)<BR> (SETvar "CMDECHO" 0)<BR> (INITGET (+ 1 2 4))<BR> (GETSS)<BR> (SETQ SS SSA)<BR> (INITGET (+ 1 2 4))<BR> (SETQ JSF (GETSTRING "\n JI SUAN FU:?<*> "))<BR> (WHILE (AND (/= JSF "+") (/= JSF "-") (/= JSF "*") (/= JSF "/") (/= JSF ""))<BR> (GETSTRING "JI SUAN FU:?<*> "))<BR> (IF (= JSF "") (SETQ JSF "*"))<BR> (SETQ XI (GETREAL "\n XI SHU:?"))<BR> (SETQ P0 (CDR (ASSOC 10 (ENTGET (SSNAME SS 0)))))<BR> (SETvar "BLIPMODE" 0)<BR> (INITGET (+ 1 2 4))<BR> (SETQ PP0 (GETPOINT "\n TEXT-POINT:?"))<BR> (SETvar "BLIPMODE" 0)<BR> (SETQ WS (GETINT "\n XIAO SHU WEI:?<1> "))<BR> (IF (= WS NIL) (SETQ WS 1))<BR> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR> (SETQ NN (SSLENGTH SS))<BR> (SETQ II 0)<BR> (WHILE (< II NN)<BR> (SETQ ENT (ENTGET (SETQ NAME (SSNAME SS II))))<BR> (SETQ TXT (CDR (ASSOC 1 ENT)))<BR> (SETQ TXT (ATOF TXT))<BR> (COND ((= JSF "+") (SETQ TXT (+ TXT XI)))<BR> ((= JSF "-") (SETQ TXT (- TXT XI)))<BR> ((= JSF "*") (SETQ TXT (* TXT XI))) <BR> ((= JSF "/") (SETQ TXT (/ TXT XI)))<BR> )<BR> (COMMAND "COPY" NAME "" P0 PP0)<BR> (SETQ TXT (RTOS TXT 2 WS))<BR> (setq txt-style (cdr (assoc 7 (entget name))))<BR> (setq style-higth (cdr (assoc 40 (tblsearch "style" txt-style))))<BR> (if (= style-higth 0.0)<BR> (COMMAND "CHANGE" "L" "" "" "" "" "" "" TXT )<BR> (command "change" "l" "" "" "" "" "" txt))<BR> (SETQ II (+ II 1))<BR> )<BR> (SETvar "BLIPMODE" 0)<BR> (SETvar "CMDECHO" 0)<BR> (PRINC)<BR> )<BR>(DEFUN C:HZZ(/ NN II ENT NAME TXT PP P0 PP0 NAME1<BR> P ST ZH ZW ANG I N W TEMP)<BR> (SETvar "BLIPMODE" 0)<BR> (SETvar "CMDECHO" 0)<BR> (PROMPT "\n FIRST-SSGET:")<BR> (INITGET (+ 1 2 4))<BR> (getss)<BR> (SETQ SS1 ssa)<BR> (PROMPT "\n SECOND-SSGET:")<BR> (getss)<BR> (SETQ SS2 ssa)<BR> <BR> (SETQ P0 (CDR (ASSOC 10 (ENTGET (SETQ NAME0 (SSNAME SS1 0))))))<BR> (INITGET (+ 1 2 4)) <BR> (SETQ PP0 (GETPOINT "\n TEXT-POINT:?"))<BR> <BR> (INITGET(+ 1 2 4))<BR> (SETQ XI (GETREAL "\n HUI ZONG GAN JIN-- DAN WEI ZHONG:? <0.888>"))<BR> (IF (= XI NIL) (SETQ XI 0.888))</P>
<P> (SETvar "BLIPMODE" 0)<BR> (SETQ WS (GETINT "\n XIAO SHU WEI:?<2> "))<BR> (IF (= WS NIL) (SETQ WS 2))<BR> <BR> (SETQ NN1 (SSLENGTH SS1))<BR> (SETQ II 0)<BR> (SETQ TXT 0)<BR> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR> (IF (AND (/= SS2 NIL) (/= SS1 NIL)) (PROGN<BR> (SETQ NN2 (SSLENGTH SS2))<BR> (IF (>= NN1 NN2) (SETQ NN NN2) (SETQ NN NN1))<BR> (WHILE (< II NN)<BR> (SETQ ENT1 (ENTGET (SETQ NAME1 (SSNAME SS1 II))))<BR> (SETQ ENT2 (ENTGET (SETQ NAME2 (SSNAME SS2 II))))<BR> (SETQ TXT1 (CDR (ASSOC 1 ENT1)))<BR> (SETQ TXT2 (CDR (ASSOC 1 ENT2)))<BR> (SETQ TXT1 (ATOF TXT1))<BR> (SETQ TXT2 (ATOF TXT2))<BR> (IF (= TXT1 XI) (SETQ TXT (+ TXT TXT2)))<BR> (SETQ II (+ II 1))<BR> )<BR> ))<BR> (COMMAND "COPY" NAME0 "" P0 PP0)<BR> (SETQ TXT (RTOS TXT 2 WS))<BR> (setq txt-style (cdr (assoc 7 (entget name0))))<BR> (setq style-higth (cdr (assoc 40 (tblsearch "style" txt-style))))<BR> (if (= style-higth 0.0)<BR> (COMMAND "CHANGE" "L" "" "" "" "" "" "" TXT )<BR> (command "change" "l" "" "" "" "" "" txt))</P>
<P> (SETvar "BLIPMODE" 0)<BR> (SETvar "CMDECHO" 0)<BR> (PRINC)<BR> )<BR></P> 研究一下,感觉还是比较靠谱
页:
[1]