明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1080|回复: 3

[提问] 智能标注有点小问题,求改

[复制链接]
发表于 2016-9-18 23:15:15 | 显示全部楼层 |阅读模式
这个程序标注线性时,不能识别多义线。另外,想让它能识别弧角270度的圆弧,标注为M,,,即螺纹孔,不懂弄,想恳求各位帮忙改一下,谢谢各位

(defun BZERR (st)
  (if (/= st "Function cancelled")
    (princ (strcat "\nError: " st))
  )
  (command ".undo" "e")
  (SETVAR "OSMODE" OS)
  (SETVAR "cmdecho" CM)
  (SETVAR "auprec" au)
  (SETVAR "luprec" lu)
  (SETVAR "ORTHOMODE" TH)
  (setq *error* olderr)
  (princ)
)
(defun C:22 (/ olderr OS CM AU LU TH A P1 C J JJ X Y d D1 D2 p2 p3 p pp wo)
  (setq olderr *error*
*error* BZERR)
  (setvar "DIMZIN" 2)
  (setvar "DIMASZ" 1)
  (setvar "DIMSCALE" 0.4)
  (SETQ OS (GETVAR "OSMODE"))
  (SETQ CM (GETVAR "CMDECHO"))
  (SETQ TH (GETVAR "ORTHOMODE"))
  (SETQ au (GETVAR "auprec"))
  (SETQ lu (GETVAR "luprec"))
  (SETVAR "CMDECHO" 0)
  (SETVAR "auprec" 4)
  (SETVAR "luprec" 4)
  (while t
    (setq a (nentsel "\n选取圆/圆弧/直线:"))
    (if  (= a v) (princ "\n程序已退出"))
     (if  (= a v) (quit))
    (if (/= a nil)
      (princ "\n")
    )
    (while (= a nil)
      (setq a (nentsel "\n请重新选择"))
      (if (/= a nil)
(princ "\n")
      )
    )
    (setq p1 (car (cdr a)))
    (setq c (ENTGET (HANDENT (cdr (assoc 5 (entget (car a)))))))
    (setq j (cdr (assoc 0 c)))
    (COND
      ((= J "LINE") (CE))
      ((= J "ARC") (AR))
      ((= J "LWPOLYLINE") (PR))
      ((= J "CIRCLE") (CI))
    )
  )
  (SETVAR "OSMODE" OS)
  (SETVAR "CMDECHO" CM)
  (SETVAR "ORTHOMODE" TH)
  (setq *error* olderr)
  (princ)
)
(DEFUN CE ()
  (command ".undo" "g")
  (setq x (cdr (assoc 10 c)))
  (setq y (cdr (assoc 11 c)))
  (setq d (atof (angtos (angle x y) 0 2)))
  (while (> d 45)
    (setq d (abs (- 90 d)))
  )
  (if (= d 45) (ang)
    (progn
      (setq d1 d)
      (setq d1 (rtos d1 2 2))
      (setq d2 (strcat d1 "%%d"))
      (SETVAR "ORTHOMODE" 0)
      (setvar "osmode" 512)
      (if  (= d 0) (df))
      (command "_dimaligned" x y PAUSE)
    )
  )
  (command ".undo" "e")
  (princ)
)
(DEFUN DF ()
(setvar "DIMDEC" 2)
(setq en_data (entget (car a)))
(setq pt1 (cdr (assoc 10 en_data)))
(setq pt2 (cdr (assoc 11 en_data)))
(setq pab (polar pt1 pi 1))
(setq paa (polar pt2 pi 1))
(command "_DIMLINEAR" x y PAUSE)  
(quit))
(DEFUN CI ()
(setvar "DIMDEC" 2)
(command "_dimdiameter" P1 PAUSE))
(DEFUN AR ()
(setvar "DIMDEC" 2)
(command "_dimradius" P1 PAUSE))
(DEFUN PR ()
(setvar "DIMDEC" 2)
(command "_dimradius" P1 PAUSE))
(defun ang ()
  (command ".undo" "g")
  (setq p2 (cadr (assoc 10 c)))
  (setq p3 (cadr (assoc 11 c)))
  (setq p (rtos (abs (- p3 p2)) 2 2))
  (setq pp (strcat (rtos d 2 2) "%%d"))
  (setq p (strcat "C" p))
  (SETVAR "ORTHOMODE" 0)
  (setvar "osmode" 512)
  (if (= "" )
    (command "LEADER" p1 pause "" p "")
    (command "LEADER" p1 pause "" pp "")
  )
  (command ".undo" "e")
  (setvar "DIMZIN" 2)
)

发表于 2016-9-19 09:13:49 | 显示全部楼层
好东西  哈伦裤
发表于 2016-10-10 10:10:13 | 显示全部楼层
标注全局比例总改为0.4,能不改最好

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2016-10-12 17:22:57 | 显示全部楼层
有现成的了,你合并一下吧,我也不会
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;标注类

;ZZXXQQ 2011-5-30 http://bbs.mjtd.com/thread-87170-1-1.html
;;对象是螺纹层且≧268°<360°标M
;;φM R 智能标注 ZZXXQQ 2011.5.2
(defun c:cmr()
;(qq1)(setq strx "cmr")
;;------------------------------------------------------
(defun shuliang ()
(princ "\n左键1,右键两次2,右键+左键3,空格4,.0=10,+0=20,-0=30,*0=40,/0=50,按0输入数量")
(setq S?L (grread))
(cond
((= (car S?L) 25) (S?L2))          ;右键
((= (car S?L) 3) ())                  ;左键
((= (cadr S?L) 32) (setq SL 4))  ;空格4
((= (cadr S?L) 48) (S?LX))       ;0输入数量

((= (cadr S?L) 50) (setq SL 2))
((= (cadr S?L) 51) (setq SL 3))
((= (cadr S?L) 52) (setq SL 4))
((= (cadr S?L) 53) (setq SL 5))
((= (cadr S?L) 54) (setq SL 6))
((= (cadr S?L) 55) (setq SL 7))
((= (cadr S?L) 56) (setq SL 8))
((= (cadr S?L) 57) (setq SL 9))

  ((= (cadr S?L) (ascii "."));2014.05.08 1040850191
   (setq S?L (grread))(cond        ;10
     ((= (cadr S?L) 48) (setq SL 10))
     ((= (cadr S?L) 49) (setq SL 11))
     ((= (cadr S?L) 50) (setq SL 12))
     ((= (cadr S?L) 51) (setq SL 13))
     ((= (cadr S?L) 52) (setq SL 14))
     ((= (cadr S?L) 53) (setq SL 15))
     ((= (cadr S?L) 54) (setq SL 16))
     ((= (cadr S?L) 55) (setq SL 17))
     ((= (cadr S?L) 56) (setq SL 18))
     ((= (cadr S?L) 57) (setq SL 19)) ))

  ((= (cadr S?L) (ascii "+"))        ;20
   (setq S?L (grread))(cond
     ((= (cadr S?L) 48) (setq SL 20))
     ((= (cadr S?L) 49) (setq SL 21))
     ((= (cadr S?L) 50) (setq SL 22))
     ((= (cadr S?L) 51) (setq SL 23))
     ((= (cadr S?L) 52) (setq SL 24))
     ((= (cadr S?L) 53) (setq SL 25))
     ((= (cadr S?L) 54) (setq SL 26))
     ((= (cadr S?L) 55) (setq SL 27))
     ((= (cadr S?L) 56) (setq SL 28))
     ((= (cadr S?L) 57) (setq SL 29)) ))

  ((= (cadr S?L) (ascii "-"))        ;30
   (setq S?L (grread))(cond
     ((= (cadr S?L) 48) (setq SL 30))
     ((= (cadr S?L) 49) (setq SL 31))
     ((= (cadr S?L) 50) (setq SL 32))
     ((= (cadr S?L) 51) (setq SL 33))
     ((= (cadr S?L) 52) (setq SL 34))
     ((= (cadr S?L) 53) (setq SL 35))
     ((= (cadr S?L) 54) (setq SL 36))
     ((= (cadr S?L) 55) (setq SL 37))
     ((= (cadr S?L) 56) (setq SL 38))
     ((= (cadr S?L) 57) (setq SL 39)) ))

  ((= (cadr S?L) (ascii "*"))        ;40
   (setq S?L (grread))(cond
     ((= (cadr S?L) 48) (setq SL 40))
     ((= (cadr S?L) 49) (setq SL 41))
     ((= (cadr S?L) 50) (setq SL 42))
     ((= (cadr S?L) 51) (setq SL 43))
     ((= (cadr S?L) 52) (setq SL 44))
     ((= (cadr S?L) 53) (setq SL 45))
     ((= (cadr S?L) 54) (setq SL 46))
     ((= (cadr S?L) 55) (setq SL 47))
     ((= (cadr S?L) 56) (setq SL 48))
     ((= (cadr S?L) 57) (setq SL 49)) ))

  ((= (cadr S?L) (ascii "/"))        ;50
   (setq S?L (grread))(cond
     ((= (cadr S?L) 48) (setq SL 50))
     ((= (cadr S?L) 49) (setq SL 51))
     ((= (cadr S?L) 50) (setq SL 52))
     ((= (cadr S?L) 51) (setq SL 53))
     ((= (cadr S?L) 52) (setq SL 54))
     ((= (cadr S?L) 53) (setq SL 55))
     ((= (cadr S?L) 54) (setq SL 56))
     ((= (cadr S?L) 55) (setq SL 57))
     ((= (cadr S?L) 56) (setq SL 58))
     ((= (cadr S?L) 57) (setq SL 59)) ))
))

(defun S?LX ()
(setq SL (getint "\n个数:")))

(defun S?L2 ()
(setq S?L (getpoint "\n左键3,右键2"))
(if S?L (setq SL 3) (setq SL 2)))

(defun S?L4 ()
(setq SL 4))
  ;;-----------------------------------------------------------------
;;;师兄 QQ361865648 2014.04.18
  ;;取曲线长度
  (defun getlength (cv)
    (vlax-curve-getDistAtParam cv (vlax-curve-getEndParam cv))
  )
  ;;弧长半径求圆心角,返回十进制角度
  (defun ca (arclen rad)
    (* 180.0 (/ (/ arclen rad) pi))
  )
  ;;-----------------------------------------------------------------
  (setvar "dimpost" ".") ;标注无前后缀
(setvar"dimazin" 2)      ;标注消除后导0
  (while (and (setq s1 (entsel "\n选择圆或圆弧 :"))
       (setq arc (car s1))
       (setq ent (entget arc))
       (wcmatch (setq tn (cdr (assoc 0 ent))) "ARC,CIRCLE")
  )
    (setq pt1 (cadr s1))
    (setq SLtxt (if
    (shuliang) ;数量

     (strcat (itoa SL) "-")
     ""
  )
    )
    (if (= tn "ARC")
      (progn
(setq cenang (ca (getlength arc) (cdr (assoc 40 ent)))) ;圆心角
(setq layer(cdr(assoc 8 ent)));图层
(setq r (cdr (assoc 40 ent)))
(if (and (>= cenang 268.0) (or (= layer "螺纹")(= layer "1虚线")))
   (progn
     (setq SLtxt (strcat SLtxt "M" (rtos (+ r r) 2)))
     (command "DIMDIAMETER" pt1 "T" SLtxt PAUSE)
   )
   (command "DIMRADIUS" pt1 "T" (strcat SLtxt "<>") PAUSE);R
)
      )
      (command "DIMDIAMETER" pt1 "T" (strcat SLtxt "<>") PAUSE);ф
    )
  )
  (princ)
)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-12-23 18:24 , Processed in 0.194531 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表