求一个数字求和程序
本帖最后由 新新小兵 于 2014-11-25 19:33 编辑http://bbs.mjtd.com/data/attachment/album/201411/25/193121k365j6v5hiq78qqv.jpg帮一个朋友的忙,求一个等号后面的数字求和的程序,
谢谢 命令 ttx 只适用于一个单行文字中有一个数字 叮咚 发表于 2014-10-31 17:58 static/image/common/back.gif
命令 ttx 只适用于一个单行文字中有一个数字
已经搞定了,多谢 CAD内置CAL命令 本帖最后由 yinchuan99001 于 2015-12-22 12:05 编辑
(DEFUN C:csum()
(setq v1 (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "units" 2 1 "" "" "" "")
(PROMPT "请选择需改动的数字")
(setq s1 (ssget '((0 . "text")) ))
(setq n (sslength s1))
(SETQ SS (GETREAL "1:倍数,2:求总和,3:加和,4:条件加和,5:列相乘" ))
(WHILE (= SS 1)
(CHT1 S1 N)
(SETQ SS 7)
)
(WHILE (= SS 2)
(CHT2 S1 N)
(SETQ SS 7)
)
(WHILE (= SS 3)
(CHT3 S1 N)
(SETQ SS 7)
)
(WHILE (= SS 4)
(CHT4 S1 N)
(SETQ SS 7)
)
(WHILE (= SS 5)
(CHT5 S1 N)
(SETQ SS 7)
)
(setvar "cmdecho" v1)
)
(defun CHT1(S1, N)
(setq wid1 (getreal "请输入文字的倍数: " ))
(setq i 0)
(repeat n
(setq e (entget (ssname s1 i )))
(setq tt1 (cdr (assoc 1 e)))
(setq tt2 (atof tt1))
(setq tt3 (* tt2 wid1))
(setq tt4tt3)
(setq tt5 (RTOS tt4))
(setq t5 (cons 1 tt5))
(setq e1 (subst t5 (assoc 1 e) e))
(entmod e1)
(setq i (+ i 1))
)
)
(defun CHT2(S1, N)
;;(setq wid1 (getreal "请输入文字的倍数: " ))
(setq i 0)
(SETQ SS 0.00)
(repeat n
(setq e (entget (ssname s1 i )))
(setq tt1 (cdr (assoc 1 e)))
(setq tt2 (atof tt1))
(SETQ SS (+ SS TT2))
(setq i (+ i 1))
)
(PRINT SS)
)
(defun CHT3(S1, N)
(setq wid1 (getreal "请输入文字的加数: " ))
(setq i 0)
(repeat n
(setq e (entget (ssname s1 i )))
(setq tt1 (cdr (assoc 1 e)))
(setq tt2 (atof tt1))
(setq tt3 (+ tt2 wid1))
(setq tt4 (FIX tt3))
(setq tt5 (itoa tt4))
(setq t5 (cons 1 tt5))
(setq e1 (subst t5 (assoc 1 e) e))
(entmod e1)
(setq i (+ i 1))
)
)
(defun CHT4(S1, N)
(setq wid1 (getreal "请输入数字的加数: " ))
(setq wid2 (getreal "请输入数字的起始数: " ))
(setq i 0)
(repeat n
(setq e (entget (ssname s1 i )))
(setq tt1 (cdr (assoc 1 e)))
(setq tt2 (atof tt1))
(WHILE (>= TT2 35)
(setq tt3 (+ tt2 wid1))
(setq tt4 (FIX tt3))
(setq tt5 (itoa tt4))
(setq t5 (cons 1 tt5))
(setq e1 (subst t5 (assoc 1 e) e))
(entmod e1)
(SETQ TT2 19)
)
(setq i (+ i 1))
)
)
(defun CHT5(S1, N)
;;(command "units" 2 1 "" "" "" "")
(PROMPT "请选择需被乘的一列数字")
(setq s2 (ssget '((0 . "text")) ))
(setq i 0)
(repeat n
(setq e (entget (ssname s1 i )))
(setq tt1 (cdr (assoc 1 e)))
(setq tt2 (atof tt1))
(setq xx1 (assoc 10 e))
(setq xy1(caddr xx1))
(setq xx1(cadr xx1))
(setq j 0)
(setq liang 1e1000)
(setq deltx 1e1000)
(setq delty 1e1000)
(repeat n
(setq ee (entget (ssname s2 j )))
(setq xy (assoc 10 ee))
(setq xy2(caddr xy))
(setq xx2 (cadr xy))
(while (< (abs (- xy2 xy1)) delty)
(setq delty (abs (- xy2 xy1)))
(setq liang (ATOF (cdr (assoc 1 ee))))
(setq deltx (abs (- xx1 xx2)))
(setq xy2 (+ deltyxy1))
)
(setq j (+ j 1))
)
(setq tt3 (* tt2 liang))
(setq tt4tt3)
(setq tt5 (rtos tt4))
(setq t5 (cons 1 tt5))
(setq e (subst t5 (assoc 1 e) e))
(setq xx1 (+ (* 2 deltx) xx1))
(setq xy1 (caddr (assoc 10 e)) )
(setq xy (list 10 xx1 xy1 0 ))
(setq e2 (subst xy (assoc 10 e) e))
(entmake e2)
(setq i (+ i 1))
)
);引用www.biyacad/club只作学习之用 ;
页:
[1]