明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3341|回复: 12

带有字符的数值求和

[复制链接]
发表于 2015-10-24 10:58:46 | 显示全部楼层 |阅读模式
1明经币
如图,希望能实现点选红色框的文字,实现求和
.                    
附件: 您需要 登录 才可以下载或查看,没有账号?注册

最佳答案

发表于 2015-10-24 10:58:47 | 显示全部楼层
游客,本帖隐藏的内容需要发帖数高于 5 才可浏览,你当前发帖数只有 0
回复

使用道具 举报

 楼主| 发表于 2015-10-24 13:19:43 | 显示全部楼层
ZZXXQQ 发表于 2015-10-24 13:15
[/post]

并不能用。而且你的只支持“加”开头的。我已经找到了能用的了。不过还是谢谢你。
回复

使用道具 举报

 楼主| 发表于 2015-10-24 13:20:45 | 显示全部楼层
ZZXXQQ 发表于 2015-10-24 13:15
[/post]

;;;;;;**************************************框选数字结尾文本求和
(defun c:qh(/ all endno aa bb cc wz tha tsum i)
  (if (null xzz) (setq xzz 0))
  (yy-emk-yb)  
  (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 zggg (cdr (assoc 40 bb)))
    (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)))
  (setq rk (rtos tsum))
(SETQ PO (getpoint "\n指定文本输出位置:"))
  (COMMAND "TEXT" PO zggg 0 rk)
  (print)
)
(defun yy-emk-yb nil
    (if (not (tblobjname "Style" "公司标准"))
        (entmake
            '((0 . "Style")(100 . "AcDbSymbolTableRecord")
                (100 . "AcDbTextStyleTableRecord")
                (2 . "公司标准")(70 . 0)(40 . 0)(41 . 0.8)(50 . 0)(71 . 0)
                (42 . 0)(3 . "hztxt_e.shx")(4 . "hztxt.shx"))
        )
    )
    (setvar "TextStyle" "公司标准")
    (princ)
)
;;;
(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)
)
回复

使用道具 举报

 楼主| 发表于 2015-10-24 13:23:00 | 显示全部楼层
ZZXXQQ 发表于 2015-10-24 13:15
[/post]

像这种能不能实现点选求和?成8+加7+墙4+钉9+管5+引4+接8
回复

使用道具 举报

 楼主| 发表于 2015-10-29 19:52:46 | 显示全部楼层


;;;;;;**************************************框选数字结尾文本求和
(defun c:qh(/ all endno aa bb cc wz tha tsum i)
  (if (null xzz) (setq xzz 0))
  (yy-emk-yb)  
  (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 zggg (cdr (assoc 40 bb)))
    (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)))
  (setq rk (rtos tsum))
(SETQ PO (getpoint "\n指定文本输出位置:"))
  (COMMAND "TEXT" PO zggg 0 rk)
  (print)
)
(defun yy-emk-yb nil
    (if (not (tblobjname "Style" "公司标准"))
        (entmake
            '((0 . "Style")(100 . "AcDbSymbolTableRecord")
                (100 . "AcDbTextStyleTableRecord")
                (2 . "公司标准")(70 . 0)(40 . 0)(41 . 0.8)(50 . 0)(71 . 0)
                (42 . 0)(3 . "hztxt_e.shx")(4 . "hztxt.shx"))
        )
    )
    (setvar "TextStyle" "公司标准")
    (princ)
)
;;;
(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)
)
回复

使用道具 举报

发表于 2015-10-30 12:16:54 | 显示全部楼层
顶楼上,支持12m+15m+18m这样的求和更好
回复

使用道具 举报

发表于 2015-12-12 18:22:25 | 显示全部楼层
果然强大啊。谢谢分享。
回复

使用道具 举报

发表于 2016-3-17 18:13:46 | 显示全部楼层
支持12m+15m+18m这样的求和更好
回复

使用道具 举报

发表于 2016-6-5 21:12:54 | 显示全部楼层
楼主很强大啊。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-2-23 21:01 , Processed in 0.337982 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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