帮忙修改数值求和
请帮忙修改,文字在数值后面求和,或数值前后都有文字的求和(print "文本数字求和(型如:钉23,钉23.12,23.12,钉,多行文字先炸开,不支持负数),命令:txtsum")
(defun c:txtsum(/ all endno aa bb cc wz tha tsum i)
(if (null xzz) (setq xzz 0))
(setq ALL (ssget(list (cons 0 "text"))))
(if all (SETQ nn (SSLENGTH ALL)))
(setq endno 0)
(setq tsum 0 i 0)
(WHILE (and (< endno nn) all)
(setq aa (ssname all endno))
(setq bb (entget aa))
(setq cc(cdr(assoc 1 bb)))
(setq wz(rdata cc))
(setq tha(substr cc (+ wz 1) ( - (strlen cc) wz -1)))
(if (= tha "") (setq tha "0"))
(setq tsum(+ tsum (atof tha)))
(setq i(1+ i))
(print (strcat (itoa i) ":文本 <" cc ">---数字 <" tha ">"))
(setq endno (+ endno 1))
)
(print (strcat "共" (itoa i) "个文本,和=" (rtos tsum)))
(print)
)
;;;
(defun rdata(str / len i aa)
(if (> (strlen str) 0)
(progn
(setq i (strlen str))
(setq aa(substr str (strlen str) 1))
(while (and (or (and (>= aa "0") (<= aa "9"))
(= aa ".")
)
(>= i 1)
)
(setq i(1- i))
(if (>= i 1) (setq aa(substr str i 1)))
)
)
)
(setq i i)
)
(defun c:txtsum(/ i lm-str2ch num ss str tha tsum)
(defun lm-Str2ch (String / positioni YPOutString)
(setq positioni -1 aiilst'() jci 0)
(repeat (strlen string)
(setq ascm(vl-string-elt string (setq positioni (+ positioni 1))))
(if (or(< 47 ascm 58)(= ascm 45)(= ascm 46)(= ascm 32))
(setq aiilst(append aiilst (list ascm)))
(setq jci (1+ jci))
)
)
(car(mapcar'vl-list->string(reverse (list aiilst))))
)
(setq ss (ssget '((0 . "text"))))
(if ss
(progn
(setq num (sslength ss))
(setq tsum 0 i 0)
(while (< i num)
(setq str(cdr(assoc 1 (entget (ssname ss i)))))
(setq tha(lm-Str2ch str))
(if (= tha "") (setq tha "0"))
(setq tsum(+ tsum (atof tha)))
(setq i(1+ i))
(princ (strcat "\n" (itoa i) ":文本 <" str ">---数字 <" tha ">"))
)
(princ (strcat "\n共" (itoa i) "个文本,和=" (rtos tsum)))
)
)
(princ)
)
(princ "\n文本数字求和(型如:钉23,钉23钉,钉23.12,-23.12,钉,多行文字先炸开,支持负数),命令:txtsum")
(princ) 飞雪神光 发表于 2023-4-7 22:19
最后可以添加在指定位置放置文字,方便计算
页:
[1]