明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1140|回复: 2

一个数字相加的程序,大家看看错在哪~!

[复制链接]
发表于 2011-2-19 18:17:29 | 显示全部楼层 |阅读模式
(defun c:tat ( / ss filter mspace n e str asclst strs add pt txt txth)
  (defun *error* (msg) (if ss (x_draw ss 4)) (setq *error* oerr))
  (princ "\n选择要计算的文本:")
  (setq oerr *error*
        ss (ssget '((0 . "*TEXT")))
        filter "0123456789.-+"
        mspace (vla-get-modelspace(vla-get-activedocument (vlax-get-
acad-object)))
        str nil strs nil)
  (if ss
    (repeat (setq n (sslength ss))
      (x_draw ss 3)
      (setq n (1- n)
            e (ssname ss n)
            str (vla-get-textstring(vlax-ename->vla-object e))
            strs (strcat (if strs strs " ") (x_txt2 str) " ")) ;;排除mtext bug.v1.1-2004.1
      )
    )
  (if (and ss (/= "" strs))
    (progn
      (setq add (eval (read (strcat "(+ " strs ")"))))
      (princ "\n文本数字和为: ")(princ add)
      (if (setq pt (getpoint "\n标注位置<重新计算>:"))
          (progn
            (setq prec (getint "\n精度(小数位数):")
                  txt (rtos add 2 prec)
                  txth (getdist "\n字高:"))
            (vla-addtext mspace txt (vlax-3D-point pt) txth)
            (x_draw ss 4)
            (princ) add)
          (progn (if ss (x_draw ss 4))(xtcal))  ;多次<重新计算>可以作为一个简易统计查看器.
      )
    )
    (progn (princ "\n!空选集或文本中无有效数字!\n") nil)
  )
)
;;
(defun x_draw (ss key / n e)
  (if (= 'PICKSET (type ss))
    (repeat (setq n (sslength ss))
      (setq n (1- n)
            e (ssname ss n))
      (redraw e key)
    )
  )
)
;;
(defun x_txt2 (str / i key1 key2 str1)
(setq i 1 key2 nil)
(repeat (strlen str)
(cond
((= "{\\f" (substr str i 3)) (setq i (+ 3 i) key1 1 key2 1))
((and key1 (= "}" (substr str i 1))) (setq key1 nil key2 nil))
((and key1 (= ";" (substr str i 1))) (setq key2 nil))
((not key2)
(setq st (substr str i 1)
str1 (strcat (if (not str1) "" str1)
(cond
((= "." st)(if (wcmatch (substr str (1+ i) 1) "#") st " "))
((member st '("+" "-")) (if (wcmatch (substr str (1+ i) 1) "#,'.") st "
"))
(T (if (wcmatch filter (strcat "*" st "*")) st " "))
)
))
)
)
(setq i (1+ i))
)
(setq str str1)
)
发表于 2011-2-19 20:25:36 | 显示全部楼层
回复 liujiayi6v 的帖子

你这是给大家出考题呐!我运行了一下,可以得到结果!程序代码内容没具体看!你要让人帮你看程序的问题,起码你得把你运行中有什么问题告诉别人,别人才能帮你!你就把一段代码搁这儿,让别人帮你看,谁有时间帮你一行一行去分析代码!
发表于 2012-5-4 11:06:29 | 显示全部楼层
我运行了没什么反映,没结果![em0]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-7-23 12:05 , Processed in 0.178412 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表