单行文字的四则运算
本帖最后由 feng582304 于 2011-4-7 01:10 编辑之前在论坛里看到有讨论四则运算的,俺刚好也要用到,就做了一个,大家一起玩玩看,呵。
用法:用单选文字写出等式,比如“1+(2*(3/(4-5)))=”,运行命令后会在等式后面写出结果“-5”
;======================计算等式======================
(defun c:ys ( / ss ss1 n txt po doc p1 p2 nn hi )
(setq doc (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
(setq ss1 (ssget '((0 . "text"))))
(setq nn 0)
(repeat (sslength ss1)
(vla-getboundingbox(vlax-ename->vla-object (ssname ss1 nn)) 'p1 'p2)
(setq p1 (vlax-safearray->list p1))
(setq p2 (vlax-safearray->list p2))
(setq po (list (+ 100 (car p2)) (cadr p1) 0))
(setq ss (vla-get-textstring (vlax-ename->vla-object (ssname ss1 nn))))
(setq hi (vla-get-height (vlax-ename->vla-object (ssname ss1 nn))))
(setq n 1)
(setq txt "")
(repeat (strlen ss)
(cond
((and (> (ascii (substr ss n 1)) 47) (< (ascii (substr ss n 1)) 58))
(setq txt (strcat txt (substr ss n 1)))
)
((= (substr ss n 1) ".")
(setq txt (strcat txt "."))
)
((or (= (substr ss n 1) "X") (= (substr ss n 1) "*") (= (substr ss n 1) "x"))
(setq txt (strcat txt "*"))
)
((= (substr ss n 1) "+")
(setq txt (strcat txt "+"))
)
((= (substr ss n 1) "-")
(setq txt (strcat txt "-"))
)
((= (substr ss n 1) "/")
(setq txt (strcat txt "/"))
)
((= (substr ss n 1) "(")
(setq txt (strcat txt "("))
)
((= (substr ss n 1) ")")
(setq txt (strcat txt ")"))
)
)
(setq n (1+ n))
)
(princ txt)
(if (null cal)(arxload"geomcal"))
(vla-addtext doc (rtos (c:cal txt) 2 2) (vlax-3d-point po) hi)
(setq nn (1+ nn))
)
(princ)
)
进来看看,顺便顶下.... 支持,我正好需要,谢谢楼主 谢谢楼主{:1_1:}{:1_1:}
页:
[1]