(defun c:gcbz() (setq ss (entget (car (entsel)))) (setq gcdh (getstring "\n 输入公差带代号:")) (setq p (getpoint "\n 输入插入点:"))
(setq dim (cdr (assoc 1 ss)))
(setq dim1 dim)
(progn
(if (= (substr dim 1 1) "R") (setq dim1 (substr dim 2)))
(if (= (substr dim 1 1) "r") (setq dim1 (substr dim 2)))
(if (= (substr dim 1 3) "%%c") (setq dim1 (substr dim 4)))
(if (= (substr dim 1 4) "\\A1;") (setq dim1 (substr dim 5)))
(if (or (= (substr dim 1 5) "\\A1;R") (= (substr dim 1 5) "\\A1;r")) (setq
dim1 (substr dim 6)))
(if (= (substr dim 1 7) "\\A1;\\U+") (setq dim1 (substr dim 12)))
);获取各类尺寸的尺寸数值
(setq dimt (atof dim1))
(setq k (record dimt));调用函数,获取数据行号
(read k "d:/data.txt");读取数据 (if (= gcdh "") (setq gc11 (getreal "\n 输入上偏差:") gc22 (getreal "\n 输入下偏差:"))
)
(if (= gcdh "f6") (setq gc11 h2 gc22 h3))
(if (= gcdh "h7") (setq gc11 h1 gc22 h4)) ;取得上、下偏差值 …… ; 以下数行从略 (setq gc1 (rtos gc11 2 4) gc2 (rtos gc22 2 4))
(setq txth (cdr (assoc 40 ss)));
(setq angr (cdr (assoc 50 ss)))
(setq hi (* txth 0.5))
(setq angd (* (/ angr pi) 180))
(setq p1 (polar p (+ (/ pi 2) angr) 0.2))
(setq p2 (polar p1 (+ (* pi 1.5) angr) (+ hi 0.8)))
(setq p3 (polar p1 angr 1.8))
(setq tole (strcat "%%p" gc1))
(if (> gc11 0) (setq gc1 (strcat "+" gc1)))
(if (> gc22 0) (setq gc2 (strcat "+" gc2)))
(if (= (abs gc11) (abs gc22)) (command "text" p2 txth angd tole ""))
(if (/= (abs gc11) (abs gc22))
(progn
(command "text" p1 hi angd gc1 "")
(command "text" p2 hi angd gc2 "")
)
)
) 本程序已在AutoCAD R14、AutoCAD2000上调试通过,可函盖全部机械设计中的公差标注类型,可大大提高标注尺寸公差的速度。
将常用的公差数值以数据文件形式存贮,利用Autolisp语言编程,自动检索尺寸公差数值来实现尺寸公差的自动标注,是一种很好的手段