1. (defun C:MBWP(/ bf-list-split-3d break_obj edta ename ent eptlst getptlst interwithpt ss startbreak);;;c:MyBreakWithPolygon
    2. (vl-load-com)
    3. (setvar "CMDECHO" 0)
    4. ;;借用函数
    5. (defun break_obj (ent brkptlst / brkobjlst closedobj en enttype maxparam minparam obj obj2break p1param p2 p2param)
    6. (setq obj2break ent brkobjlst (list ent) enttype (cdr (assoc 0 (entget ent))))
    7. (foreach brkpt brkptlst
    8. ;; get last entity created via break in case multiple breaks
    9. (if brkobjlst
    10. (progn
    11. ;; if pt not on object x, switch objects
    12. (if (not (numberp (vl-catch-all-apply 'vlax-curve-getdistatpoint (list obj2break brkpt)))
    13. )
    14. (foreach obj brkobjlst ; find the one that pt is on
    15. (if (numberp (vl-catch-all-apply 'vlax-curve-getdistatpoint (list obj brkpt)))
    16. (setq obj2break obj) ; switch objects
    17. )
    18. )
    19. )
    20. )
    21. )
    22. ;; Handle any objects that can not be used with the Break Command
    23. ;; using one point, gap of 0.000001 is used
    24. (cond
    25. ((and (or (= "LWPOLYLINE" enttype) (= "SPLINE" enttype)) ; only closed splines
    26. (vlax-curve-isclosed obj2break))
    27. (setq p1param (vlax-curve-getparamatpoint obj2break brkpt) p2 (vlax-curve-getpointatparam obj2break (+ p1param 0.000001)))
    28. (command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans p2 0 1))
    29. )
    30. ((= "CIRCLE" enttype) ; break the circle
    31. (setq p1param (vlax-curve-getparamatpoint obj2break brkpt) p2 (vlax-curve-getpointatparam obj2break (+ p1param 0.000001)))
    32. (command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans p2 0 1))
    33. (setq enttype "ARC")
    34. )
    35. ((and (= "ELLIPSE" enttype) ; only closed ellipse
    36. (vlax-curve-isclosed obj2break))
    37. ;; Break the ellipse, code borrowed from Joe Burke 6/6/2005
    38. (setq
    39. p1param (vlax-curve-getparamatpoint obj2break brkpt)
    40. p2param (+ p1param 0.000001)
    41. minparam (min p1param p2param)
    42. maxparam (max p1param p2param)
    43. obj (vlax-ename->vla-object obj2break)
    44. )
    45. (vlax-put obj 'startparameter maxparam)
    46. (vlax-put obj 'endparameter (+ minparam (* pi 2)))
    47. )
    48. ;;==================================
    49. (t ; Objects that can be broken
    50. (setq closedobj (vlax-curve-isclosed obj2break))
    51. (command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans brkpt 0 1))
    52. (if (not closedobj) ; new object was created
    53. (setq brkobjlst (cons (entlast) brkobjlst))
    54. )
    55. )
    56. )
    57. )
    58. )
    59. (defun InterWithPt(ent1 ent2 / bf-list-split-3d var)
    60. (defun BF-list-split-3d (lst)
    61. (if lst (cons (list (car lst) (cadr lst) (caddr lst)) (BF-list-split-3d (cdddr lst))))
    62. )
    63. (if (> (vlax-safearray-get-u-bound (setq var (vlax-variant-value (vla-IntersectWith (vlax-ename->vla-object ent1) (vlax-ename->vla-object ent2) acExtendNone))) 1) 1)
    64. (BF-list-split-3d (vlax-safearray->list var))
    65. nil
    66. )
    67. )
    68. (defun getptlst(e) (mapcar 'cdr (vl-remove-if-not (function (lambda(x) (= 10 (car x)))) (entget e))))
    69. (defun BF-list-split-3d (lst)
    70. (if lst (cons (list (car lst) (cadr lst) (caddr lst)) (BF-list-split-3d (cdddr lst))))
    71. )
    72. (defun startbreak(ent ss / ient inlst n)
    73. (setq n -1)
    74. (while (setq ient (ssname ss (setq n (1+ n))))
    75. (if (setq inlst (InterWithPt ent ient))
    76. (break_obj ient inlst)
    77. )
    78. )
    79. )
    80. (command "_.UNDO" "be")
    81. (if (setq ent (car (entsel "\n请选择【直线】或者【由多段线构成的多边形】:")))
    82. (progn
    83. (setq ename (cdr (assoc 0 (setq edta (entget ent)))))
    84. (cond
    85. ((equal ename "LINE")
    86. (setq ss (ssdel ent (ssget "F" (list (cdr (assoc 10 edta)) (cdr (assoc 11 edta))) '((0 . "LINE,LWPOLYLINE,SPLINE,CIRCLE,ARC,ELLIPSE")))))
    87. (startbreak ent ss)
    88. )
    89. ((equal ename "LWPOLYLINE")
    90. (if (<= (length (setq eptlst (getptlst ent))) 2)
    91. (setq ss (ssdel ent (ssget "F" eptlst '((0 . "LINE,LWPOLYLINE,SPLINE,CIRCLE,ARC,ELLIPSE")))))
    92. (setq ss (ssdel ent (ssget "CP" (append eptlst (list (car eptlst))) '((0 . "LINE,LWPOLYLINE,SPLINE,CIRCLE,ARC,ELLIPSE")))))
    93. )
    94. (startbreak ent ss)
    95. )
    96. )
    97. )
    98. )
    99. (command "_.UNDO" "e")
    100. (prin1)
    101. )
    102. (defun C:MBWP1(/ bf-list-split-3d breakapt ent getptlst ient inlst interwithpt n ss);c:MyBreakWithPolygon
    103. (vl-load-com)
    104. (setvar "CMDECHO" 0)
    105. (defun breakapt(ent elst iptlst / ilst)
    106. (foreach e elst
    107. (if (setq ilst (InterWithPt ent e))
    108. (foreach p ilst
    109. (if (not (member p iptlst))
    110. (progn
    111. (command "_.BREAK" e "_non" (trans p 0 1) "_non" (trans p 0 1))
    112. ;(command "_.BREAK" e p "@")
    113. (breakapt
    114. ent
    115. (if (and (= 1 (length (setq ips (InterWithPt ent e)))) (equal (car ips) p 1e-8))
    116. (vl-remove e (cons (entlast) elst))
    117. (if (and (= 1 (length (setq ips (InterWithPt ent (entlast))))) (equal (car ips) p 1e-8))
    118. elst
    119. (cons (entlast) elst)
    120. )
    121. )
    122. (cons p iptlst)
    123. )
    124. )
    125. )
    126. )
    127. )
    128. )
    129. )
    130. (defun InterWithPt(ent1 ent2 / bf-list-split-3d var)
    131. (defun BF-list-split-3d (lst)
    132. (if lst (cons (list (car lst) (cadr lst) (caddr lst)) (BF-list-split-3d (cdddr lst))))
    133. )
    134. (if (> (vlax-safearray-get-u-bound (setq var (vlax-variant-value (vla-IntersectWith (vlax-ename->vla-object ent1) (vlax-ename->vla-object ent2) acExtendNone))) 1) 1)
    135. (BF-list-split-3d (vlax-safearray->list var))
    136. nil
    137. )
    138. )
    139. (defun getptlst(e) (mapcar 'cdr (vl-remove-if-not (function (lambda(x) (= 10 (car x)))) (entget e))))
    140. (defun BF-list-split-3d (lst)
    141. (if lst (cons (list (car lst) (cadr lst) (caddr lst)) (BF-list-split-3d (cdddr lst))))
    142. )
    143. (defun startbreak(ent ss / ient inlst n)
    144. (setq n -1)
    145. (while (setq ient (ssname ss (setq n (1+ n))))
    146. (if (setq inlst (InterWithPt ent ient))
    147. (breakapt ent (list ient) '())
    148. )
    149. )
    150. )
    151. (command "_.UNDO" "be")
    152. (if (setq ent (car (entsel "\n请选择【直线】或者【由多段线构成的多边形】:")))
    153. (progn
    154. (setq ename (cdr (assoc 0 (setq edta (entget ent)))))
    155. (cond
    156. ((equal ename "LINE")
    157. (setq ss (ssdel ent (ssget "F" (list (cdr (assoc 10 edta)) (cdr (assoc 11 edta))) '((0 . "LINE,LWPOLYLINE,SPLINE,CIRCLE,ARC,ELLIPSE")))))
    158. (startbreak ent ss)
    159. )
    160. ((equal ename "LWPOLYLINE")
    161. (if (<= (length (setq eptlst (getptlst ent))) 2)
    162. (setq ss (ssdel ent (ssget "F" eptlst '((0 . "LINE,LWPOLYLINE,SPLINE,CIRCLE,ARC,ELLIPSE")))))
    163. (setq ss (ssdel ent (ssget "CP" (append (setq eptlst (getptlst ent)) (list (car eptlst))) '((0 . "LINE,LWPOLYLINE,SPLINE,CIRCLE,ARC,ELLIPSE")))))
    164. )
    165. (startbreak ent ss)
    166. )
    167. )
    168. )
    169. )
    170. (command "_.UNDO" "e")
    171. (prin1)
    172. )