明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 686|回复: 5

[源码] 标注尺寸与标高值相加

[复制链接]
发表于 2021-9-9 12:44 | 显示全部楼层 |阅读模式
  1. (DEFUN C:KK()
  2. (setq jd (getint "input 精度<0.000>:"))
  3. (if (= jd nil) (setq jd 0))
  4. (princ "\nselect object:")
  5. (setq s (ssget))
  6. (setq n (sslength s))
  7. (setq k 0 )(setq mm 0.0)
  8. (while (< k n)
  9.       (setq name (ssname s k))
  10.       (setq a (entget name))
  11.       (setq t1 (assoc '0 a))
  12.       (setq t1 (cdr t1))
  13.       (if (= t1 "TEXT") (PROGN
  14.           (setq tx (assoc '1 a))
  15.           (setq tx (cdr tx))
  16.           (setq tx (atof tx))
  17.           (setq mm (+ tx mm))
  18.          ))
  19.       (if (= t1 "DIMENSION") (PROGN
  20.           (setq tx (assoc '1 a))
  21.           (setq tx (cdr tx))
  22.           (if (and (/= tx "")(/= tx "<>"))(setq tx (atof tx)))
  23.           (if (or (= tx "")(= tx "<>"))(progn
  24.               (setq tx (assoc '42 a))
  25.               (setq tx (cdr tx))
  26.         ;(setq tx (/ tx 1000))
  27.               ))
  28.           (if (= k 0) (setq MM TX) (setq mm (+ tx mm)))
  29.          ))
  30.       (setq k (+ k 1))
  31. )
  32. (setq mm (rtos mm 2 jd))
  33. (setq po (getpoint "\n指定计算结果的写入点:"))
  34. (command "text" po ""  "" mm)
  35. )
这个程序可以选择尺寸标注与标高值相加,但有个小数点取值不正确的问题,比如尺寸值是4000,标高值是5.200,程序执行后的结果是4005,而正确的数值应该是9.200,请完善一下这个程序
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2021-9-9 13:51 | 显示全部楼层
(setq tx (atof tx))改为 (setq tx (* 1000 (atof tx)))
 楼主| 发表于 2021-9-9 14:17 | 显示全部楼层
kkq0305 发表于 2021-9-9 13:51
(setq tx (atof tx))改为 (setq tx (* 1000 (atof tx)))

谢谢
还有一个小问题,尺寸标注4000,标高5.200,结果是9200.如果让结果变成9.200
发表于 2021-9-9 15:05 | 显示全部楼层
szx025 发表于 2021-9-9 14:17
谢谢
还有一个小问题,尺寸标注4000,标高5.200,结果是9200.如果让结果变成9.200

用动态块吧,没有这么多烦恼,也不用编程
 楼主| 发表于 2021-9-9 15:39 | 显示全部楼层
  1. (DEFUN C:KK()
  2. ;(setq jd (getint "input 精度<0.000>:"))
  3. (if (= jd nil) (setq jd 3))  ;设置小数点后的数字位数
  4. (princ "\nselect object:")
  5. (setvar "DIMZIN" 1)
  6. (setq s (ssget))
  7. (setq n (sslength s))
  8. (setq k 0 )(setq mm 0.0)
  9. (while (< k n)
  10.       (setq name (ssname s k))
  11.       (setq a (entget name))
  12.       (setq t1 (assoc '0 a))
  13.       (setq t1 (cdr t1))
  14.       (if (= t1 "TEXT") (PROGN
  15.           (setq tx (assoc '1 a))
  16.           (setq tx (cdr tx))
  17.            (setq tx (* 1000 (atof tx)))
  18.           (setq mm (+ tx mm))
  19.          ))
  20.       (if (= t1 "DIMENSION") (PROGN
  21.           (setq tx (assoc '1 a))
  22.           (setq tx (cdr tx))
  23.           (if (and (/= tx "")(/= tx "<>"))(setq tx (atof tx)))
  24.           (if (or (= tx "")(= tx "<>"))(progn
  25.               (setq tx (assoc '42 a))
  26.               (setq tx (cdr tx))
  27.               ;(setq tx (/ tx 1000))  ;读取的标注数值除1000
  28.               ))
  29.           (if (= k 0) (setq MM TX) (setq mm (+ tx mm)))
  30.          ))
  31.       (setq k (+ k 1))
  32. )
  33. (setq mm (/ mm 1000))
  34. (setq mm (rtos mm 2 jd))
  35. (setq po (getpoint "\n指定计算结果的写入点:"))
  36. (command "text" po ""  "" mm)
  37. )
搞定了,
但运用范围想广一点,如果数字中带字符(SX=-88)怎么提取出其中的数字,再执行程序
发表于 2021-9-10 09:20 | 显示全部楼层
自贡黄明儒 发表于 2021-9-9 15:05
用动态块吧,没有这么多烦恼,也不用编程

大师能否展示一个
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-19 10:40 , Processed in 0.284500 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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