1. ;;说明:消除合并重复直线程序(【直线消重】分离于=>***消除合并重复直线、圆弧或圆yad_undup*** YAD建筑")
    2. ;;参数:ss:需要消重的选择集
    3. ;;返回:消重后的选择集
    4. (defun remore(sss / chg_ent dxf on_ent os pmt sdel tang undup)
    5. (defun dxf(ent i)
    6. (cdr (assoc i (entget ent)))
    7. )
    8. (defun tang(ang sty)
    9. (rem (+ (* 2 pi) ang) sty)
    10. )
    11. (defun chg_ent(ent i pt / en)
    12. (setq en (entget ent) en (subst (cons i pt) (assoc i en) en))
    13. (entmod en)
    14. )
    15. (defun on_ent(a a1 a2)
    16. (equal (+ (distance a1 a) (distance a a2)) (distance a1 a2) 0.01)
    17. )
    18. (defun undup(s / c ent ent1 ent2 ept1 ept2 m n nm sdels spt1 spt2 ss)
    19. (setq n -1 nm 0 sdels s)
    20. (while (setq ent1 (ssname s (setq n (1+ n))))
    21. (if (entget ent1)
    22. (progn
    23. (setq spt1 (dxf ent1 10) ept1 (dxf ent1 11))
    24. (if (setq ss (ssget "cp" (list (polar spt1 (angle ept1 spt1) 0.1)
    25. (polar ept1 (- (angle spt1 ept1) (/ pi 4)) 0.15)
    26. (polar ept1 (+ (angle spt1 ept1) (/ pi 4)) 0.15)
    27. ) '((0 . "line"))
    28. )
    29. )
    30. (progn
    31. (ssdel ent1 ss)
    32. (setq m -1 c (sslength ss))
    33. (repeat c
    34. (setq ent (ssname ss (setq m (1+ m))))
    35. (if (not (ssmemb ent s))
    36. (progn
    37. (ssdel ent ss)
    38. (setq m (1- m))
    39. )
    40. )
    41. )
    42. (setq m -1 c (sslength ss))
    43. (repeat c
    44. (setq ent2 (ssname ss (setq m (1+ m))))
    45. (setq spt2 (dxf ent2 10) ept2 (dxf ent2 11))
    46. (cond
    47. ((and (on_ent spt2 spt1 ept1) (on_ent ept2 spt1 ept1))
    48. (entdel ent2)
    49. (if (ssmemb ent2 sdels) (ssdel ent2 sdels))
    50. )
    51. ((and (on_ent spt1 spt2 ept2) (on_ent ept1 spt2 ept2))
    52. (entdel ent1)
    53. (if (ssmemb ent1 sdels) (ssdel ent1 sdels))
    54. (setq ent1 ent2 spt1 spt2 ept1 ept2)
    55. )
    56. ((and (equal (tang (angle spt1 ept1) pi) (tang (angle spt2 ept2) pi) 0.001)
    57. (or (on_ent spt2 spt1 ept1) (on_ent ept2 spt1 ept1))
    58. )
    59. (entdel ent2)
    60. (if (ssmemb ent2 sdels) (ssdel ent2 sdels))
    61. (progn
    62. (if (on_ent spt2 spt1 ept1)
    63. (setq spt2 ept2)
    64. )
    65. (if (> (distance spt1 spt2) (distance ept1 spt2))
    66. (progn (chg_ent ent1 11 spt2) (setq ept1 spt2))
    67. (progn (chg_ent ent1 10 spt2) (setq spt1 spt2))
    68. )
    69. )
    70. )
    71. (T (setq nm (1- nm)))
    72. )
    73. (setq nm (1+ nm))
    74. )
    75. )
    76. )
    77. )
    78. )
    79. )
    80. sdels
    81. )
    82. (command "_.undo" "_be")
    83. (command "_.ucs" "")
    84. (setq os (getvar "osmode") sdel (ssadd))
    85. (setvar "cmdecho" 0)
    86. (setvar "osmode" 0)
    87. (if (> (sslength sss) 1) (progn (setq sdel (undup sss)) (setq pmt T)) (setq sdel sss))
    88. (if (and sss (not pmt)) sss)
    89. (setvar "osmode" os)
    90. (command "_.undo" "_e")
    91. sdel
    92. )