szx025 发表于 2021-9-9 12:44:58

标注尺寸与标高值相加

(DEFUN C:KK()
(setq jd (getint "input 精度<0.000>:"))
(if (= jd nil) (setq jd 0))
(princ "\nselect object:")
(setq s (ssget))
(setq n (sslength s))
(setq k 0 )(setq mm 0.0)
(while (< k n)
      (setq name (ssname s k))
      (setq a (entget name))
      (setq t1 (assoc '0 a))
      (setq t1 (cdr t1))
      (if (= t1 "TEXT") (PROGN
          (setq tx (assoc '1 a))
          (setq tx (cdr tx))
          (setq tx (atof tx))
          (setq mm (+ tx mm))
         ))
      (if (= t1 "DIMENSION") (PROGN
          (setq tx (assoc '1 a))
          (setq tx (cdr tx))
          (if (and (/= tx "")(/= tx "<>"))(setq tx (atof tx)))
          (if (or (= tx "")(= tx "<>"))(progn
            (setq tx (assoc '42 a))
            (setq tx (cdr tx))
      ;(setq tx (/ tx 1000))
            ))
          (if (= k 0) (setq MM TX) (setq mm (+ tx mm)))
         ))
      (setq k (+ k 1))
)
(setq mm (rtos mm 2 jd))
(setq po (getpoint "\n指定计算结果的写入点:"))
(command "text" po """" mm)
)这个程序可以选择尺寸标注与标高值相加,但有个小数点取值不正确的问题,比如尺寸值是4000,标高值是5.200,程序执行后的结果是4005,而正确的数值应该是9.200,请完善一下这个程序

kkq0305 发表于 2021-9-9 13:51:01

(setq tx (atof tx))改为 (setq tx (* 1000 (atof tx)))

szx025 发表于 2021-9-9 14:17:30

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:08

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

用动态块吧,没有这么多烦恼,也不用编程

szx025 发表于 2021-9-9 15:39:34

(DEFUN C:KK()
;(setq jd (getint "input 精度<0.000>:"))
(if (= jd nil) (setq jd 3));设置小数点后的数字位数
(princ "\nselect object:")
(setvar "DIMZIN" 1)
(setq s (ssget))
(setq n (sslength s))
(setq k 0 )(setq mm 0.0)
(while (< k n)
      (setq name (ssname s k))
      (setq a (entget name))
      (setq t1 (assoc '0 a))
      (setq t1 (cdr t1))
      (if (= t1 "TEXT") (PROGN
          (setq tx (assoc '1 a))
          (setq tx (cdr tx))
         (setq tx (* 1000 (atof tx)))
          (setq mm (+ tx mm))
         ))
      (if (= t1 "DIMENSION") (PROGN
          (setq tx (assoc '1 a))
          (setq tx (cdr tx))
          (if (and (/= tx "")(/= tx "<>"))(setq tx (atof tx)))
          (if (or (= tx "")(= tx "<>"))(progn
            (setq tx (assoc '42 a))
            (setq tx (cdr tx))
              ;(setq tx (/ tx 1000));读取的标注数值除1000
            ))
          (if (= k 0) (setq MM TX) (setq mm (+ tx mm)))
         ))
      (setq k (+ k 1))
)
(setq mm (/ mm 1000))
(setq mm (rtos mm 2 jd))
(setq po (getpoint "\n指定计算结果的写入点:"))
(command "text" po """" mm)
)搞定了,
但运用范围想广一点,如果数字中带字符(SX=-88)怎么提取出其中的数字,再执行程序

cghdy 发表于 2021-9-10 09:20:00

自贡黄明儒 发表于 2021-9-9 15:05
用动态块吧,没有这么多烦恼,也不用编程

大师能否展示一个
页: [1]
查看完整版本: 标注尺寸与标高值相加