找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 840|回复: 8

[每日一码] 数字文字求和

[复制链接]

已领礼包: 19个

财富等级: 恭喜发财

发表于 2017-1-5 15:48:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
(defun C:STX (/ cpent elist en ip newtxt pt ss sum sumtxt txt)
  (princ "\n\t\t>>>  Select text to get summ >>>")
  (if
    ;;select texts/mtexts on screen :
    (setq ss (ssget '((0 . "*TEXT"))))
     ;; if selected then :
     (progn
       ;; store the first text entity for using 'em further :
       (setq cpent (ssname ss 0))
       ;; set initial sum to zero :
       (setq sum 0.)
       ;; loop trough selected texts/mtexts :
       (while
         ;; get the first text in selection :
         (setq en (ssname ss 0))
          ;; get entity list of them :
          (setq elist (entget en))
          ;; get the textstring by key 1 from entity list :
          (setq txt (cdr (assoc 1 elist)))
          ;; create output string :
          (setq        sumtxt
                 ;; concatenate strings :
                 (strcat
                   ;; convert digits to string :
                   (rtos
                     ;; add to summ the digital value of text :
                     (setq sum (+ (atof txt) sum))
                     ;; 2 is for metric units (3 for engineering) :
                     2
                     ;; set precision by current :
                     (getvar "dimdec")
                   )
                 )
          )
          ;; delete entity from selection set :
          (ssdel en ss)
       )
       ;; display message in the command line:
       (princ (strcat "\nSumm=" sumtxt))
       (setq pt (getpoint "\nSpecify the new text location: "))
       ;; get the insertion point of stored entity :
       (setq ip (cdr (assoc 10 (entget cpent))))
       ;; copy text entity to the new destination point :
       (command "_copy" cpent "" ip pt)
       ;; get the last created entity :
       (setq newtxt (entlast))
       ;; get entity list of them :
       (setq elist (entget newtxt))
       ;; modify entity list with new text string :
       (entmod (subst (cons 1 sumtxt) (assoc 1 elist) elist))
       ;; update changes :
       (entupd newtxt)
     )
  )
  (princ)
)
(princ "\nStart command with STX...")
(princ)

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 19个

财富等级: 恭喜发财

 楼主| 发表于 2017-1-5 15:52:01 | 显示全部楼层
另外一个版本,屏幕打印求和结果

(defun c:add (/ txtss badset total cntr ent elist str nstr)
  (setvar "cmdecho" 0)
  (setq        total 0
        cntr  0
        nstr  (list)
  )
  (princ "\nSelect numbers to add: ")
  (setq txtss (ssget '((0 . "TEXT"))))
  (while (< cntr (sslength txtss))
    (setq ent        (ssname txtss cntr)
          elist        (entget ent)
    )
    (setq str (cdr (assoc 1 elist)))
    (if        (and (> (strlen str) 3) (wcmatch str "*`,*"))
      (repeat (/ (strlen str) 4)
        (setq nstr (cons (substr str (- (strlen str) 2) 3) nstr))
        (setq str (substr str 1 (- (strlen str) 4)))
      )                                        ;repeat
    )                                        ;if
    (if        nstr
      (foreach v nstr
        (setq str (strcat str v))
      )
    )                                        ;if
    (setq total (+ total (atof str)))
    (setq cntr (1+ cntr))
    (setq nstr (list))
  )                                        ;while
  (princ (strcat "\nTotal: " (rtos total 2 2)))
  (setvar "cmdecho" 0)
  (princ)
)                                        ;eof

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 3个

财富等级: 恭喜发财

发表于 2017-1-5 22:17:59 | 显示全部楼层
下载!学习学习!谢谢!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 87个

财富等级: 招财进宝

发表于 2017-1-6 12:56:05 | 显示全部楼层
确实是难得好帖啊,顶先
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2017-1-10 09:28:10 | 显示全部楼层
快捷键是??????????
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复

使用道具 举报

已领礼包: 8742个

财富等级: 富甲天下

发表于 2017-1-10 11:33:56 | 显示全部楼层

下载!学习!谢谢!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 6468个

财富等级: 富甲天下

发表于 2017-1-11 23:02:37 | 显示全部楼层
楼主一如既往的活跃。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2017-3-31 08:46:07 | 显示全部楼层
啥也不说了,感谢楼主分享哇!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2017-6-3 21:22:52 | 显示全部楼层
楼主,你好

请教,一楼那程序,,这句(entmod (subst (cons 1 sumtxt) (assoc 1 elist) elist))它是如何运作的?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-23 21:18 , Processed in 0.417941 second(s), 44 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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