水果总量统计
(defun zkwb (shiming / shibiao wengben0 wengben bbb chang wenglist list1 i) ;炸开文本(command "undo" "be")
(setq shibiao (entget shiming))
(setq wengben0 (assoc 1 shibiao))
(setq wengben (cdr wengben0))
(setq bbb nil chang (strlen wengben))
(setq i 1)
(setq wenglist nil)
(while (< i chang)
(setq wengge (substr wengben i 2))
(setq wenglist (append wenglist (list wengge)))
(setq i (+ i 2))
)
(setq list1 "")
;得到文本列表wenglist
(foreach x wenglist
(if (and(>= (ascii x) 45) (<=(ascii x) 59))
(setq list1 (strcat list1 x))
)
) (princ)
(atof list1)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:tt11 ( / lst ent pts pt demj zmj i) ;求平均数
(setq lst (ssget '((0 . "text,mtext") (1 . "**") ) ))
(setq i 0)
(setq zmj 0.000)
(while(< i (sslength lst))
(setq ent (ssname lst i))
(setq demj (zkwb ent))
;(setq demj (atof(cdr (assoc 1 (entget ent)))))
(setq zmj(+ zmj demj))
(setq i (+ i 1))
)
(entmake (list (cons 0"TEXT") (cons 1 (strcat "总和"(rtos zmj 2 3) "平均数" (rtos (/ zmj i) 2 3) )) (cons 10 (getpoint "\请输入总和插入点"))
(cons 40 3)
(cons 8 "总和")
))
(print zmj)
(print (/ zmj i))
(princ)
)
;;--------------------------------------------主函数----------------------------------------------------;;
(defun xxexp (pat str key / end)
;(princ "\n ★\"一刀屠文\"(xxexp)(xxexpr) = 对字符串进行正则表达式测试及替换-by 梁雄啸.2007.7")
(vl-load-com)
(if (not *xxvbsexp)
(setq *xxvbsexp (vlax-get-or-create-object "VBScript.RegExp"))
)
(vlax-put *xxvbsexp 'Pattern pat)
(if (not key)(setq key ""))
(setq key (strcase key))
(setq keys '(("I""IgnoreCase")("G""Global")("M""Multiline")))
(mapcar '(lambda(x)
(if (wcmatch key (strcat "*" (car x) "*"))
(vlax-put *xxvbsexp (read(cadr x)) 0)
(vlax-put *xxvbsexp (read(cadr x)) -1)
))
keys)
(setq matches (vlax-invoke *xxvbsexp 'Execute str))
(vlax-for x matches (setq end (cons (vla-get-value x) end)))
(reverse end)
)
;;--------------------------------------------end----------------------------------------------------;;
;;--------------------------------------------主函数----------------------------------------------------;;
;; 用正则表达式替换字符
(defun xxexpr (pat str nstr key / end)
;(princ "\n ★\"一刀屠文\"(xxexp)(xxexpr) = 对字符串进行正则表达式测试及替换-by 梁雄啸.2007.7")
(vl-load-com)
(if (not *xxvbsexp)
(setq *xxvbsexp (vlax-get-or-create-object "VBScript.RegExp"))
)
(vlax-put *xxvbsexp 'Pattern pat)
(if (not key)(setq key ""))
(setq key (strcase key))
(setq keys '(("I""IgnoreCase")("G""Global")("M""Multiline")))
(mapcar '(lambda(x)
(if (wcmatch key (strcat "*" (car x) "*"))
(vlax-put *xxvbsexp (read(cadr x)) 0)
(vlax-put *xxvbsexp (read(cadr x)) -1)
))
keys)
(vlax-invoke *xxvbsexp 'replace str nstr)
)
(defun c:xxexphlp()
(alert
"------------------\"一刀屠文\" = 对字符串进行正则表达式测试及替换--------------------
------------------------------------by 梁雄啸.2007.7-------------------------------
函数:(xxexp pat str key)
功能 对字符串进行正则表达式匹配测试.
参数: pat = 正则表达式模式 ,对应vbs正则表达式的模式(expression)。说明: \\号要用\\\\替代.
str = 字符串
key = \"i\" \"g\" \"m\" , \"i\"不区分大小写(Ignorecase),\"g\"全局匹配(Global).
\"m\"多行模式(Multiline),以上几个关键字可以组合使用,或用 \"\".
返回: 返回匹配的字符列表,或无一匹配返回nil
函数:(xxexpr pat str nstr key)
功能 对字符串进行正则表达式替换.
参数: pat = 同xxexp
str = 被替换字符串
nstr = 替换字符串
key = 同xxexp
返回 :返回替换后的字符串.
"
)
)
(princ)
;;--------------------------------------------end----------------------------------------------------;;
(defun zkwb (shiming / shibiao wengben0 wengben bbb chang wenglist list1 i pat) ;炸开文本
(command "undo" "be")
(setq shibiao (entget shiming))
(setq wengben0 (assoc 1 shibiao))
(setq wengben (cdr wengben0))
(setq pat "[+|-]?\\d*\\.?\\d+(e[+|-]*\\d+)*")
(setq wenglist (xxexp pat wengben ""))
;得到文本列表wenglist
(princ)
(read(car wenglist))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:tt11 ( / lst ent pts pt demj zmj i) ;求平均数
(setq lst (ssget '((0 . "text,mtext") (1 . "**") ) ))
(setq i 0)
(setq zmj 0.000)
(while(< i (sslength lst))
(setq ent (ssname lst i))
(setq demj (zkwb ent))
;(setq demj (atof(cdr (assoc 1 (entget ent)))))
(setq zmj(+ zmj demj))
(setq i (+ i 1))
)
(entmake (list (cons 0"TEXT") (cons 1 (strcat "总和"(rtos zmj 2 3) "平均数" (rtos (/ zmj i) 2 3) )) (cons 10 (getpoint "\请输入总和插入点"))
(cons 40 3)
(cons 8 "总和")
))
(print zmj)
(print (/ zmj i))
(princ)
) 效果不错啊 感谢楼主分享!!!
页:
[1]