;|文本计数求和支持一个text,mtext中有多个数字字符串,
支持字符串中小数,负数 飞诗作品|;
(defun c:TextSum (/ draw GetNumb *error* a sum d filter pt ss str strs)
  (defun Draw (ss key)
    (foreach e (fsxm-ss->enlist ss) (redraw e key))
  )
  (defun GetNumb (str / filter)
    (setq filter (vl-string->list "0123456789.-+"))
    (setq str (vl-list->string
		(mapcar	'(lambda (a)
			   (if (vl-position a filter)
			     a
			     32
			   )
			 )
			(vl-string->list str)
		)
	      )
	  str (vl-string-trim " " str)
    )
    (strcat "0" str)
  )
  (defun *error* (msg)
    (if	ss
      (Draw ss 4)
    )
  )
  (princ "\n选择要计算的文本(支持*TEXT选择集):")
  (setq ss (ssget '((0 . "*TEXT"))))
  (setq strs " ")
  (or ss (fsxm-silenceexit))
  (Draw ss 3)
  (foreach e (fsxm-ss->enlist ss)
    (setq d (entget e))
    (setq str (cdr (assoc 1 d)))
    (if	(= "MTEXT" (cdr (assoc 0 d)))
      (setq str (fsxm-MStr2Str str))
    )
    (setq strs (strcat strs (GetNumb str) " "))
  )
  (if (apply '= (cons 32 (vl-string->list strs)))
    (progn
      (Draw ss 4)
      (princ "\n!没有在选取文本找到有效数字!\n")
      (fsxm-silenceexit)
    )
  )
  (setq sum (eval (read (strcat "(+ " strs ")"))))
  (setq sum (fsxm-tostring sum))
  (princ "\n文本数字和为: ")
  (princ sum)
  (if (setq pt (getpoint "\n指定标注位置:"))
    (vla-addText
      (fsxm-activespace)
      sum
      (vlax-3d-point (trans pt 1 0))
      (getvar "textsize")
    )
  )
  (Draw ss 4)
  (princ)
)


























































