CAD培训_建筑CAD培训_机械CAD培训_钢构CAD培训_电气CAD培训郑州CAD培训CAD教程
郑州清新教育是中国最全面的CAD培训机构,是CAD爱好者学习的最佳培训机构!
您现在所的位置: 网站首页 > CAD教程 > 正文

CAD中自动标注公差的方法

归属类别:CAD教程 发布时间:2012-9-1 9:16:33 录入:admin 热量值: 标签:CAD 自动标注 公差
今天郑州CAD培训为大家讲一讲自动标注公差
为使标注的尺寸公差与基本尺寸协调,在标注前先根据基本尺寸的字高、旋转角等确定出公差的字高和旋转角,并计算出上、下偏差的标注位置,然后用“Text”命令标注公差。程序在设计中,考虑到了只知道上、下偏差值而不知道公差等级和公差代号的情况(此时可不输入公差等级和代号,而直接输入上、下偏差),同时也考虑到了某些特殊情形,如±0.01等等。
源程序(文件名为gcbz..lsp)如下:

  (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语言编程,自动检索尺寸公差数值来实现尺寸公差的自动标注,是一种很好的手段