(defun C:MBWP(/ bf-list-split-3d break_obj edta ename ent eptlst getptlst interwithpt ss startbreak);;;c:MyBreakWithPolygon (vl-load-com) (setvar "CMDECHO" 0) ;;借用函数 (defun break_obj (ent brkptlst / brkobjlst closedobj en enttype maxparam minparam obj obj2break p1param p2 p2param) (setq obj2break ent brkobjlst (list ent) enttype (cdr (assoc 0 (entget ent)))) (foreach brkpt brkptlst ;; get last entity created via break in case multiple breaks (if brkobjlst (progn ;; if pt not on object x, switch objects (if (not (numberp (vl-catch-all-apply 'vlax-curve-getdistatpoint (list obj2break brkpt))) ) (foreach obj brkobjlst ; find the one that pt is on (if (numberp (vl-catch-all-apply 'vlax-curve-getdistatpoint (list obj brkpt))) (setq obj2break obj) ; switch objects ) ) ) ) ) ;; Handle any objects that can not be used with the Break Command ;; using one point, gap of 0.000001 is used (cond ((and (or (= "LWPOLYLINE" enttype) (= "SPLINE" enttype)) ; only closed splines (vlax-curve-isclosed obj2break)) (setq p1param (vlax-curve-getparamatpoint obj2break brkpt) p2 (vlax-curve-getpointatparam obj2break (+ p1param 0.000001))) (command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans p2 0 1)) ) ((= "CIRCLE" enttype) ; break the circle (setq p1param (vlax-curve-getparamatpoint obj2break brkpt) p2 (vlax-curve-getpointatparam obj2break (+ p1param 0.000001))) (command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans p2 0 1)) (setq enttype "ARC") ) ((and (= "ELLIPSE" enttype) ; only closed ellipse (vlax-curve-isclosed obj2break)) ;; Break the ellipse, code borrowed from Joe Burke 6/6/2005 (setq p1param (vlax-curve-getparamatpoint obj2break brkpt) p2param (+ p1param 0.000001) minparam (min p1param p2param) maxparam (max p1param p2param) obj (vlax-ename->vla-object obj2break) ) (vlax-put obj 'startparameter maxparam) (vlax-put obj 'endparameter (+ minparam (* pi 2))) ) ;;================================== (t ; Objects that can be broken (setq closedobj (vlax-curve-isclosed obj2break)) (command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans brkpt 0 1)) (if (not closedobj) ; new object was created (setq brkobjlst (cons (entlast) brkobjlst)) ) ) ) ) ) (defun InterWithPt(ent1 ent2 / bf-list-split-3d var) (defun BF-list-split-3d (lst) (if lst (cons (list (car lst) (cadr lst) (caddr lst)) (BF-list-split-3d (cdddr lst)))) ) (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) (BF-list-split-3d (vlax-safearray->list var)) nil ) ) (defun getptlst(e) (mapcar 'cdr (vl-remove-if-not (function (lambda(x) (= 10 (car x)))) (entget e)))) (defun BF-list-split-3d (lst) (if lst (cons (list (car lst) (cadr lst) (caddr lst)) (BF-list-split-3d (cdddr lst)))) ) (defun startbreak(ent ss / ient inlst n) (setq n -1) (while (setq ient (ssname ss (setq n (1+ n)))) (if (setq inlst (InterWithPt ent ient)) (break_obj ient inlst) ) ) ) (command "_.UNDO" "be") (if (setq ent (car (entsel "\n请选择【直线】或者【由多段线构成的多边形】:"))) (progn (setq ename (cdr (assoc 0 (setq edta (entget ent))))) (cond ((equal ename "LINE") (setq ss (ssdel ent (ssget "F" (list (cdr (assoc 10 edta)) (cdr (assoc 11 edta))) '((0 . "LINE,LWPOLYLINE,SPLINE,CIRCLE,ARC,ELLIPSE"))))) (startbreak ent ss) ) ((equal ename "LWPOLYLINE") (if (<= (length (setq eptlst (getptlst ent))) 2) (setq ss (ssdel ent (ssget "F" eptlst '((0 . "LINE,LWPOLYLINE,SPLINE,CIRCLE,ARC,ELLIPSE"))))) (setq ss (ssdel ent (ssget "CP" (append eptlst (list (car eptlst))) '((0 . "LINE,LWPOLYLINE,SPLINE,CIRCLE,ARC,ELLIPSE"))))) ) (startbreak ent ss) ) ) ) ) (command "_.UNDO" "e") (prin1))(defun C:MBWP1(/ bf-list-split-3d breakapt ent getptlst ient inlst interwithpt n ss);c:MyBreakWithPolygon (vl-load-com) (setvar "CMDECHO" 0) (defun breakapt(ent elst iptlst / ilst) (foreach e elst (if (setq ilst (InterWithPt ent e)) (foreach p ilst (if (not (member p iptlst)) (progn (command "_.BREAK" e "_non" (trans p 0 1) "_non" (trans p 0 1)) ;(command "_.BREAK" e p "@") (breakapt ent (if (and (= 1 (length (setq ips (InterWithPt ent e)))) (equal (car ips) p 1e-8)) (vl-remove e (cons (entlast) elst)) (if (and (= 1 (length (setq ips (InterWithPt ent (entlast))))) (equal (car ips) p 1e-8)) elst (cons (entlast) elst) ) ) (cons p iptlst) ) ) ) ) ) ) ) (defun InterWithPt(ent1 ent2 / bf-list-split-3d var) (defun BF-list-split-3d (lst) (if lst (cons (list (car lst) (cadr lst) (caddr lst)) (BF-list-split-3d (cdddr lst)))) ) (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) (BF-list-split-3d (vlax-safearray->list var)) nil ) ) (defun getptlst(e) (mapcar 'cdr (vl-remove-if-not (function (lambda(x) (= 10 (car x)))) (entget e)))) (defun BF-list-split-3d (lst) (if lst (cons (list (car lst) (cadr lst) (caddr lst)) (BF-list-split-3d (cdddr lst)))) ) (defun startbreak(ent ss / ient inlst n) (setq n -1) (while (setq ient (ssname ss (setq n (1+ n)))) (if (setq inlst (InterWithPt ent ient)) (breakapt ent (list ient) '()) ) ) ) (command "_.UNDO" "be") (if (setq ent (car (entsel "\n请选择【直线】或者【由多段线构成的多边形】:"))) (progn (setq ename (cdr (assoc 0 (setq edta (entget ent))))) (cond ((equal ename "LINE") (setq ss (ssdel ent (ssget "F" (list (cdr (assoc 10 edta)) (cdr (assoc 11 edta))) '((0 . "LINE,LWPOLYLINE,SPLINE,CIRCLE,ARC,ELLIPSE"))))) (startbreak ent ss) ) ((equal ename "LWPOLYLINE") (if (<= (length (setq eptlst (getptlst ent))) 2) (setq ss (ssdel ent (ssget "F" eptlst '((0 . "LINE,LWPOLYLINE,SPLINE,CIRCLE,ARC,ELLIPSE"))))) (setq ss (ssdel ent (ssget "CP" (append (setq eptlst (getptlst ent)) (list (car eptlst))) '((0 . "LINE,LWPOLYLINE,SPLINE,CIRCLE,ARC,ELLIPSE"))))) ) (startbreak ent ss) ) ) ) ) (command "_.UNDO" "e") (prin1))