找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2032|回复: 3

[求助] 求修改标注对齐避让程序

[复制链接]

已领礼包: 106个

财富等级: 日进斗金

发表于 2013-12-17 10:07:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
  1. ;;==>>><<<==标注对齐
  2. (defun c:cv (/ ent ent0 entlstx entlsty i p0 p0x p0y p10 p13 p70 ptx pty sc slen snap ss xsw)
  3.   (setvar "osmode" 1)
  4.   (WHILE (setq ss (ssget '((0 . "DIMENSION")))
  5.         DIMhighscale 1
  6.         ent (ssname ss 0)
  7.         ent (entget ent)
  8.         p10 (cdr (assoc 10 ent))
  9.         p13 (cdr (assoc 13 ent))
  10.         p111 (getpoint "\n指定对齐点, 或<右键退出>:")
  11.         p0 (trans p111 1 0)
  12.         pts (+ 0 (getvar "DIMTXT") (getvar "DIMscale"))
  13.         DIMhigh (- pts 0)
  14.         SC 1
  15. )
  16.   (setvar "osmode" 247)
  17.   (setvar "cmdecho" 0)
  18.   (COMMAND ".UNDO" "BE")
  19.   (setq os (getvar "osmode")
  20.         xsw (getvar "DIMZIN")
  21. )
  22.   (setvar "DIMZIN" 0)
  23.   (if p0
  24.     (progn
  25.       (setvar "osmode" 0)
  26.       (setq p0x (car p0)
  27.             p0y (cadr p0)
  28.       )
  29.       (setq entlstX '()
  30.             entlstY '()
  31.             PTX '()
  32.             PTY '()
  33.       )
  34.       (setq slen (sslength ss)
  35.             I 0
  36.       )
  37.       (while (ssname ss I)
  38.         (setq ent0 (ssname ss I))
  39.         (setq ent (entget ent0))
  40.         (setq p70 (cdr (assoc 70 ent))
  41.               p13 (cdr (assoc 13 ent))
  42.         )
  43.         (cond
  44.           ((= p70 102.0)
  45.             (setq entlstX (cons ent0 entlstX)
  46.                   PTX (cons p13 PTX)
  47.             )
  48.           )
  49.           ((= p70 38.0)
  50.             (setq entlstY (cons ent0 entlstY)
  51.                   PTY (cons p13 PTY)
  52.             )
  53.           )
  54.           (t
  55.             (exit)
  56.           )
  57.         )
  58.         (setq I (+ 1 I))
  59.       )
  60.      (setq PTX (ymdq-01 PTX))
  61.      (setq PTY (ymdq-02 PTY))
  62.       (if (/= entlstX '())
  63.         (progn
  64.           (setq entlstX (ymdq-03 entlstX PTX))
  65.           (ymdq-04 entlstX P0 P10 SC)
  66.           (ymdq-06 entlstX p10)
  67.         )
  68.       )
  69.       (if (/= entlstY '())
  70.         (progn
  71.           (setq entlstY (ymdq-03 entlstY PTY))
  72.           (ymdq-05 entlstY P0 P10 SC)
  73.           (ymdq-07 entlstY p10)
  74.         )
  75.       )
  76.       (setvar "osmode" os)
  77.     )
  78.    )
  79.   )
  80.   (vl-cmdf ".UNDO" "E")
  81.   (setvar "osmode" os)
  82.   (setvar "DIMZIN" xsw)
  83.   (princ)
  84. )
  85. ;;; 提炼 X 坐标,并排序
  86. (defun ymdq-01 (LST_PT / e1 e2 i lst_x lstl pt tmp x y)
  87.   (setq LST_X '())
  88.   (foreach PT LST_PT
  89.     (setq X (car PT)
  90.           Y (cadr PT)
  91.     )
  92.     (if (setq TMP (assoc X LST_X))
  93.       (setq LST_X (subst
  94.                     (append
  95.                       (list X Y)
  96.                       (cdr TMP)
  97.                     )
  98.                     TMP
  99.                     LST_X
  100.                   )
  101.       )
  102.       (setq LST_X (cons (list X Y) LST_X))
  103.     )
  104.   )
  105.   (setq LST_X (mapcar
  106.                 '(lambda (E1)
  107.                    (cons (car E1) (vl-sort (cdr E1) '<))
  108.                  )
  109.                 LST_X
  110.               )
  111.   )
  112.   (setq LST_X (vl-sort LST_X '(lambda (E1 E2)
  113.                                 (< (car E1) (car E2))
  114.                               )
  115.               )
  116.   )
  117.   (setq i 0
  118.         LSTL '()
  119.   )
  120.   (while (< i (length LST_X))
  121.     (setq LSTL (cons (list (car (nth i LST_X)) (cadr (nth i LST_X)) 0.0) LSTL))
  122.     (setq i (+ 1 i))
  123.   )
  124.   (setq LST_X (reverse LSTL))
  125.   LST_X
  126. )
  127. ;;提炼 Y 坐标,并排序
  128. (defun ymdq-02 (LST_PT / e1 e2 i lst_y lstl pt tmp x y)
  129.   (setq LST_Y '())
  130.   (foreach PT LST_PT
  131.     (setq X (car PT)
  132.           Y (cadr PT)
  133.     )
  134.     (if (setq TMP (assoc Y LST_Y))
  135.       (setq LST_Y (subst
  136.                     (append
  137.                       (list Y X)
  138.                       (cdr TMP)
  139.                     )
  140.                     TMP
  141.                     LST_Y
  142.                   )
  143.       )
  144.       (setq LST_Y (cons (list Y X) LST_Y))
  145.     )
  146.   )
  147.   (setq LST_Y (mapcar
  148.                 '(lambda (E1)
  149.                    (cons (car E1) (vl-sort (cdr E1) '<))
  150.                  )
  151.                 LST_Y
  152.               )
  153.   )
  154.   (setq LST_Y (vl-sort LST_Y '(lambda (E1 E2)
  155.                                 (< (car E1) (car E2))
  156.                               )
  157.               )
  158.   )
  159.   (setq i 0
  160.         LSTL '()
  161.   )
  162.   (while (< i (length LST_Y))
  163.     (setq LSTL (cons (list (cadr (nth i LST_Y)) (car (nth i LST_Y)) 0.0) LSTL))
  164.     (setq i (+ 1 i))
  165.   )
  166.   (setq LST_Y (reverse LSTL))
  167.   LST_Y
  168. )
  169. ;;将标注图元名列表按照按照点列表顺序排序
  170. (defun ymdq-03 (entlstX PTX / entlstxl i j p13 xy)
  171.   (setq i 0
  172.         entlstXL '()
  173.   )
  174.   (while (< i (length PTX))
  175.     (setq P13 (cons 13 (nth i PTX)))
  176.     (setq j 0)
  177.     (while (< j (length entlstX))
  178.       (setq XY (entget (nth j entlstX)))
  179.       (if (member P13 XY)
  180.         (setq entlstXL (cons (nth j entlstX) entlstXL))
  181.       )
  182.       (setq j (+ 1 j))
  183.     )
  184.     (setq i (+ 1 i))
  185.   )
  186.   (setq entlstX (reverse entlstXL))
  187.   entlstX
  188. )
  189. ;;按照图元列表顺序对齐X坐标
  190. (defun ymdq-04 (entlstX P0 P10 SC / en1 ent j p0y p1 p10x p10y pt1 x x_last y)
  191.   (setq p0y (cadr P0))
  192.   (setq p10X (car P10)
  193.         p10Y (cadr P10)
  194.   )
  195.   (setq j 0)
  196.   (setq X_LAST (car (cdr (assoc 13 (entget (nth 0 entlstX))))))
  197.   (while (< j (length entlstX))
  198.     (setq ent (nth j entlstX))
  199.     (setq en1 (entget ent))
  200.     (setq P1 (cdr (assoc 13 en1)))
  201.     (setq X (car P1)
  202.           Y (cadr P1)
  203.     )
  204.     (setq X_LAST (max
  205.                    X
  206.                    X_LAST
  207.                  )
  208.     )
  209.     (setq STR  (* SC (- X p10X)))
  210.     (setq en1 (subst
  211.                 (cons 1 (rtos STR 2 2))
  212.                 (assoc 1 en1)
  213.                 en1
  214.               )
  215.     )|;
  216.     (setq PT1 (list X_LAST p0y 0.0))
  217.     (setq en1 (subst
  218.                 (cons 14 PT1)
  219.                 (assoc 14 en1)
  220.                 en1
  221.               )
  222.     )
  223.     (entmod en1)
  224.     (setq X_LAST (+ X_LAST (* DIMhighscale DIMhigh (getvar "DIMscale"))))
  225.     (setq j (+ 1 j))
  226.   )
  227. )
  228. ;;按照图元列表顺序对齐Y坐标
  229. (defun ymdq-05 (entlstY P0 P10 SC / en1 ent j p0x p1 p10x p10y pt1 x y y_last)
  230.   (setq p0x (car P0))
  231.   (setq p10X (car P10)
  232.         p10Y (cadr P10)
  233.   )
  234.   (setq j 0)
  235.   (setq Y_LAST (cadr (cdr (assoc 13 (entget (nth 0 entlstY))))))
  236.   (while (< j (length entlstY))
  237.     (setq ent (nth j entlstY))
  238.     (setq en1 (entget ent))
  239.     (setq P1 (cdr (assoc 13 en1)))
  240.     (setq X (car P1)
  241.           Y (cadr P1)
  242.     )
  243.     (setq Y_LAST (max
  244.                    Y
  245.                    Y_LAST
  246.                  )
  247.     )
  248.     (setq STR  (* SC (- Y p10Y)))
  249.     ;|(setq en1 (subst
  250.                 (cons 1 (rtos STR 2 2))
  251.                 (assoc 1 en1)
  252.                 en1
  253.               )
  254.     )|;
  255.     (setq PT1 (list p0x Y_LAST 0.0))
  256.     (setq en1 (subst
  257.                 (cons 14 PT1)
  258.                 (assoc 14 en1)
  259.                 en1
  260.               )
  261.     )
  262.     (entmod en1)
  263.     (setq Y_LAST (+ Y_LAST (* DIMhighscale DIMhigh (getvar "DIMscale"))))
  264.     (setq j (+ 1 j))
  265.   )
  266. )
  267. ;; 优化X坐标偏移
  268. (defun ymdq-06 (lsp pt / ent ent1 i il lsty lstz np14 x x_last x0 y0)
  269.   (setq X0 (car pt))
  270.   (setq Y0 (cadr pt))
  271.   (setq i 0
  272.         il 0
  273.         LSTZ '()
  274.         LSTY '()
  275.   )
  276.   (while (< i (length lsp))
  277.     (setq X (car (cdr (assoc 13 (entget (nth i lsp))))))
  278.     (if (<= X X0)
  279.       (setq LSTZ (cons (nth i lsp) LSTZ))
  280.       (setq LSTY (cons (nth i lsp) LSTY))
  281.     )
  282.     (SETQ i (+ 1 i))
  283.   )
  284.   (setq LSTZ LSTZ)
  285.   (setq LSTY (reverse LSTY))
  286.   (if (/= LSTZ '())
  287.     (progn
  288.       (setq i 0)
  289.       (setq X_LAST (car (cdr (assoc 13 (entget (nth 0 LSTZ))))))
  290.       (while (< i (length LSTZ))
  291.         (setq ent (nth i LSTZ))
  292.         (setq ent1 (entget ent))
  293.         (setq X (car (cdr (assoc 13 ent1))))
  294.         (setq X_LAST (min
  295.                        X
  296.                        X_LAST
  297.                      )
  298.         )
  299.         (setq nP14 (list X_LAST (cadr (cdr (assoc 14 ent1))) 0.0))
  300.         (setq ent1 (subst
  301.                      (cons 14 nP14)
  302.                      (assoc 14 ent1)
  303.                      ent1
  304.                    )
  305.         )
  306.         (entmod ent1)
  307.         (SETQ i (+ 1 i))
  308.         (setq X_LAST (- X_LAST (* DIMhighscale DIMhigh (getvar "DIMscale"))))
  309.       )
  310.     )
  311.   )
  312.   (if (/= LSTY '())
  313.     (progn
  314.       (setq i 0)
  315.       (setq X_LAST (+ X0 (* DIMhighscale DIMhigh (getvar "DIMscale"))))
  316.       (while (< i (length LSTY))
  317.         (setq ent (nth i LSTY))
  318.         (setq ent1 (entget ent))
  319.         (setq X (car (cdr (assoc 13 ent1))))
  320.         (setq X_LAST (max
  321.                        X
  322.                        X_LAST
  323.                      )
  324.         )
  325.         (setq nP14 (list X_LAST (cadr (cdr (assoc 14 ent1))) 0.0))
  326.         (setq ent1 (subst
  327.                      (cons 14 nP14)
  328.                      (assoc 14 ent1)
  329.                      ent1
  330.                    )
  331.         )
  332.         (entmod ent1)
  333.         (SETQ i (+ 1 i))
  334.         (setq X_LAST (+ X_LAST (* DIMhighscale DIMhigh (getvar "DIMscale"))))
  335.       )
  336.     )
  337.   )
  338. )
  339. ;; 优化Y坐标偏移
  340. (defun ymdq-07 (lsp pt / ent ent1 i il lsts lstx np14 x0 y y_last y0)
  341.   (setq X0 (car pt))
  342.   (setq Y0 (cadr pt))
  343.   (setq i 0
  344.         il 0
  345.         LSTX '()
  346.         LSTS '()
  347.   )
  348.   (while (< i (length lsp))
  349.     (setq Y (cadr (cdr (assoc 13 (entget (nth i lsp))))))
  350.     (if (<= Y Y0)
  351.       (setq LSTX (cons (nth i lsp) LSTX))
  352.       (setq LSTS (cons (nth i lsp) LSTS))
  353.     )
  354.     (SETQ i (+ 1 i))
  355.   )
  356.   (setq LSTX LSTX)
  357.   (setq LSTS (reverse LSTS))
  358.   (if (/= LSTX '())
  359.     (progn
  360.       (setq i 0)
  361.       (setq Y_LAST (cadr (cdr (assoc 13 (entget (nth 0 LSTX))))))
  362.       (while (< i (length LSTX))
  363.         (setq ent (nth i LSTX))
  364.         (setq ent1 (entget ent))
  365.         (setq Y (cadr (cdr (assoc 13 ent1))))
  366.         (setq Y_LAST (min
  367.                        Y
  368.                        Y_LAST
  369.                      )
  370.         )
  371.         (setq nP14 (list (car (cdr (assoc 14 ent1))) Y_LAST 0.0))
  372.         (setq ent1 (subst
  373.                      (cons 14 nP14)
  374.                      (assoc 14 ent1)
  375.                      ent1
  376.                    )
  377.         )
  378.         (entmod ent1)
  379.         (SETQ i (+ 1 i))
  380.         (setq Y_LAST (- Y_LAST (* DIMhighscale DIMhigh (getvar "DIMscale"))))
  381.       )
  382.     )
  383.   )
  384.   (if (/= LSTS '())
  385.     (progn
  386.       (setq i 0)
  387.       (setq Y_LAST (+ Y0 (* DIMhighscale DIMhigh (getvar "DIMscale"))))
  388.       (while (< i (length LSTS))
  389.         (setq ent (nth i LSTS))
  390.         (setq ent1 (entget ent))
  391.         (setq Y (cadr (cdr (assoc 13 ent1))))
  392.         (setq Y_LAST (max
  393.                        Y
  394.                        Y_LAST
  395.                      )
  396.         )
  397.         (setq nP14 (list (car (cdr (assoc 14 ent1))) Y_LAST 0.0))
  398.         (setq ent1 (subst
  399.                      (cons 14 nP14)
  400.                      (assoc 14 ent1)
  401.                      ent1
  402.                    )
  403.         )
  404.         (entmod ent1)
  405.         (SETQ i (+ 1 i))
  406.         (setq Y_LAST (+ Y_LAST (* DIMhighscale DIMhigh (getvar "DIMscale"))))
  407.       )
  408.     )
  409.   )
  410. )
标注对齐时有一些尺寸可以有一些不行,会出现:错误: quit / exit abort


acad.rar

18.55 KB, 下载次数: 59, 下载积分: D豆 -1 , 活跃度 1

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 106个

财富等级: 日进斗金

 楼主| 发表于 2013-12-17 10:08:37 | 显示全部楼层
cad.gif
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2018-1-25 15:56:58 | 显示全部楼层
谢谢分享谢谢分享谢谢分享谢谢分享
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2019-3-17 17:53:47 | 显示全部楼层
好人一生平安
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-23 12:29 , Processed in 0.196105 second(s), 42 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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