求LISP程序:复核总尺寸与分项尺寸总和是否一致
本帖最后由 fengyu6913 于 2023-11-10 17:45 编辑本帖最后由 Dani1988 于 2023-11-10 22:13 编辑
(defun c:tt (/ DIM1 DIM2 SUM1 SUM2)
(defun tt-get-dxf (i ssn)
(cond ((= (type ssn) 'ename) (cdr (assoc i (entget ssn))))
((= (type ssn) 'list) (cdr (assoc i ssn)))
)
)
(defun ss->LST (ss / i l)
(if ss
(repeat (setq i (sslength ss))
(setq l (cons (ssname ss (setq i (1- i))) l))
)
)
)
(princ "\n请选择总尺寸:")
(setq dim1 (car (ss->LST (ssget ":e:s" '((0 . "dim*"))))))
(princ "\n请选择分尺寸:")
(setq dim2 (ssget
'((0 . "dim*"))))
(setq sum1 (if (/= (tt-get-dxf 1 dim1) "")
(read (tt-get-dxf 1 dim1))
(tt-get-dxf 42 dim1)
)
)
(setq sum2 (apply '+
(mapcar '(lambda (x)
(if (/= (tt-get-dxf 1 x) "")
(read (tt-get-dxf 1 x))
(tt-get-dxf 42 x)
)
)
(ss->LST dim2)
)
)
)
(if (equal sum1 sum2 0.1)
(alert "相等!")
(alert (strcat "不相等! SUM=" (VL-PRINC-TO-STRING sum2)))
)
)
本帖最后由 xyp1964 于 2023-11-11 11:12 编辑
(defun c:tt ()
(defun xyp-dxf(code e)(cdr(assoc code(entget e))))
(defun xyp-Ss2List(ss)(vl-remove-if-not'(lambda(x)(equal(type x)'ENAME))(mapcar'cadr(ssnamex ss))))
(princ "\n请选择尺寸标注组<退出>: ")
(if (setq ss (ssget '((0 . "DIM*"))))
(progn
(setq lst (xyp-Ss2List ss)
lst (mapcar '(lambda (x) (if (/= (setq a (xyp-DXF 1 x)) "")(distof a)(xyp-DXF 42 x)))lst)
lst (vl-sort lst '>)
l1 (car lst)
l2(apply '+ (cdr lst))
)
(princ "\n总尺寸 = ")(princ l1)
(princ "\n分项尺寸总和 = ")(princ l2)
(if (equal l1 l2 1e-3)
(princ "\n总尺寸与分项尺寸总和一致")
(princ "\n总尺寸与分项尺寸总和不一致")
)
)
)
(princ)
)
帮你整合下上面俩个大佬的,,币给他们,命令:TT
本帖最后由 yaojing38 于 2023-11-11 19:14 编辑(defun c:tt (/ l1 l2 lst ss)
(princ "\n请选择尺寸:")
(setq ss (ssget'((0 . "DIM*"))))
(setq lst (ss2LST ss)
lst (mapcar '(lambda (x) (if (/= (setq a (dxf 1 x)) "")(distof a)(dxf 42 x)))lst)
lst (vl-sort lst '>)
l1 (car lst)
l2(apply '+ (cdr lst))
)
(princ "\n总尺寸 = ")(princ l1)
(princ "\n分项尺寸总和 = ")(princ l2)
(if (equal l1 l2 1e-3)
(princ "\n总尺寸与分项尺寸总和一致")
(princ "\n总尺寸与分项尺寸总和不一致")
)
(princ)
)
(defun dxf (i ssn)
(cond ((= (type ssn) 'ename) (cdr (assoc i (entget ssn))))
((= (type ssn) 'list) (cdr (assoc i ssn)))
)
)
(defun ss2lst (ss / i l)
(if ss
(repeat (setq i (sslength ss))
(setq l (cons (ssname ss (setq i (1- i))) l))
)
)
) 好热闹,好热闹 本帖最后由 fengyu6913 于 2023-11-13 10:11 编辑
感谢三位大神,
币就先到先得哈,没找到给另外两们大神送币的途径 yaojing38 发表于 2023-11-11 19:13
感谢热心大佬 本帖最后由 panliang9 于 2023-11-13 11:49 编辑
如果每个分尺寸都进行了圆整,举例来说,每个分尺寸都圆整了0.1,有九个分尺寸,这样的话,总尺寸的名义值和分尺寸的总和值就都差了1
这怎么整。
9(实际9.1)+9(实际9.1)+9(实际9.1)+9(实际9.1)+9(实际9.1)+9(实际9.1)+9(实际9.1)+9(实际9.1)+9(实际9.1)=82(81.9)
分尺寸名义值合=81
总尺寸名义值=82
因为我的图中出现过这种情况。 panliang9 发表于 2023-11-13 11:48
如果每个分尺寸都进行了圆整,举例来说,每个分尺寸都圆整了0.1,有九个分尺寸,这样的话,总尺寸的名义值 ...
(equal sum1 sum2 1.1)
判断一致的精度调整为1.1或更大,根据你的实际情况来改
页:
[1]