明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 7767|回复: 34

【练习题】选线打断自身以及选线打断其他线

  [复制链接]
发表于 2011-11-23 11:56 | 显示全部楼层 |阅读模式
本帖最后由 yjr111 于 2011-11-25 00:02 编辑

虽然论坛已经有很多帖子,但抛开帖子,发现纯粹自己写一个打断其实并不简单,发此贴,望高手能提供好思路。。。

(间距默认为0,即普通单点打断,命令brs)



  1. ;;;;;;;;;;;;;;;;;;与线相交交点打断;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;;;;;;;;;;;;;;;;BY YJR111 2011-11-20;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;;;;;;;;;;;;;;;;;适用于所有曲线,但多段线打断不充分;;;;;;;;;;;;;;;;;
  4. (defun c:br (/         n   e     ee       s
  5.        lst_e     vla_x   vla_y     point     vla_point
  6.        p_lst     point1   dxf10_line       dxf11_line
  7.        ee_new    ee_last  ss  sss
  8.       )
  9.   (command "_.undo" "be" )
  10.   (setq oldosmode (getvar "osmode"))
  11.   (setvar "osmode" 0)
  12.   (setvar "cmdecho" 0)
  13.   (setvar "orthomode" 0)
  14.   (setq n 0)
  15.   (setq ee_last (entlast))
  16.   (setq sss (ssadd))
  17.   (setq ee (car (entsel "\n选择一条曲线:")))
  18.   (setq vla_ee (vlax-ename->vla-object ee))
  19.   (vla-getboundingbox vla_ee 'min 'max)
  20.   (setq minpoint (vlax-safearray->list min)
  21.   maxpoint (vlax-safearray->list max)
  22.   )
  23.   ;(command "line" minpoint maxpoint "")
  24.   ;(redraw (entlast) 3)
  25.   (INITGET 128 "S O")
  26.   (SETQ  KEY
  27.    (GETKWORD
  28.      "\n 凡与所选曲线相交的曲线被打断(S)或所选曲线自身在交点被打断[O]"
  29.    ) ;_ 结束GETKWORD
  30.   ) ;_ 结束SETQ
  31.   (if (not KEY)
  32.     (setq key "S")
  33.   ) ;_ 结束if
  34.   (setq  ss (ssget "c"  maxpoint minpoint)
  35.   n  0
  36.   ) ;_ 结束setq
  37.   
  38.   (while (< n (sslength ss))
  39.     (setq e  (ssname ss n)
  40.     s  (entget e)
  41.     lst_e  (append lst_e (list e))
  42.     n  (1+ n)
  43.     ) ;_ 结束setq
  44. ;_ 结束setq
  45.   ) ;_ 结束while
  46.   (setq  n 0
  47.   i 0
  48.   ) ;_ 结束setq
  49.   (foreach y lst_e
  50.     (setq vla_y (vlax-ename->vla-object y))
  51.    
  52.     (if  (and (not (equal vla_ee vla_y))
  53.        (/= (safearray-value
  54.        (vlax-variant-value
  55.          (setq vla_point (vlax-invoke-method
  56.                vla_ee
  57.                'IntersectWith
  58.                vla_y
  59.                acExtendNone
  60.              ) ;_ 结束vlax-invoke-method
  61.          ) ;_ 结束setq
  62.        ) ;_ 结束vlax-variant-value
  63.      ) ;_ 结束safearray-value
  64.      nil
  65.        ) ;_ 结束/=
  66.   ) ;_ 结束and
  67.       (progn
  68.   (setq
  69.     point  (vlax-safearray->list (vlax-variant-value vla_point))
  70.   ) ;_ 结束setq
  71.   (if (> (length point) 3)
  72.     (progn
  73.       (setq point1 (list (nth 3 point) (nth 4 point) (last point))
  74.       p_lst   (cons point1 p_lst)
  75.       ) ;_ 结束setq
  76.       (setq point  (list (car point) (cadr point) (caddr point))
  77.       p_lst  (cons point p_lst)
  78.       ) ;_ 结束setq
  79.       (if  (= key "S")
  80.         (progn
  81.     (command "_.break" y point1 "@")
  82.     (command "_.break" y point "@")
  83.         ) ;_ 结束progn
  84. ;_ 结束progn
  85.       ) ;_ 结束if
  86.     ) ;_ 结束setq

  87.     (progn
  88.       (setq point  (vlax-safearray->list
  89.         (vlax-variant-value vla_point)
  90.       ) ;_ 结束vlax-safearray->list
  91.       ) ;_ 结束vlax-safearray->list
  92.      
  93.       (if  (not (or (equal (vlax-curve-getstartpoint vla_y) point 1e-4)
  94.                          (equal (vlax-curve-getendpoint vla_y)point 1e-4)
  95.                      )
  96.                 ) ;_ 结束not
  97.             (setq p_lst (cons point p_lst))
  98.       ) ;_ 结束setq
  99.       (if  (= key "S")
  100.         (command "_.break" y point "@")
  101.       ) ;_ 结束if
  102.     ) ;_ 结束progn
  103.   ) ;_ 结束if
  104.       ) ;_ 结束progn
  105.     ) ;_ 结束if
  106.   ) ;_ 结束foreach
  107.             (if  (= key "O")
  108.         (progn
  109.         (foreach x p_lst
  110.          (setq i 0)
  111.     (if (> (sslength sss) 0)

  112.       (while (< i (sslength sss))
  113.         (setq ee (ssname sss i))
  114.        (command "_.break" ee x "@")
  115.         (setq i (1+ i))
  116.       ) ;_ 结束while
  117.     ) ;_ 结束if
  118.     (command "_.break" ee x "@")
  119.           (ssdel ee  ss )

  120.     (setq sss  (ssget "c" minpoint maxpoint))
  121.                
  122.     (setq n 0)
  123.     (repeat  (sslength ss)
  124.       (setq i 0)
  125.       (while (< i (sslength sss))
  126.         (if  (equal (ssname ss n) (ssname sss i))
  127.           (progn
  128.       (ssdel (ssname sss i) sss)
  129.       (setq i (sslength sss))
  130.           ) ;_ 结束progn
  131.         ) ;_ 结束if
  132.         (setq i (1+ i))

  133.       ) ;_ 结束while
  134.       (setq n (1+ n))
  135.     ) ;_ 结束repeat
  136.          
  137.     (command "_.select" SS SSS "")
  138.     (setq ss (ssget "P"))
  139.                 )

  140.         ) ;_ 结束progn
  141.       ) ;_ 结束if
  142.   (princ (strcat "共打断<" (itoa (length p_lst)) " >个交点!"))
  143.   (setvar "osmode" oldosmode)
  144.   (command "_.undo" "end" )
  145.   (princ)
  146. ) ;_ 结束defun


本帖子中包含更多资源

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

x

点评

我当宝收藏了!非常感谢  发表于 2012-3-13 08:19

评分

参与人数 1明经币 +1 收起 理由
xyz2009xyz + 1 能否设置打断间距呢?

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2023-5-9 20:29 | 显示全部楼层
你好。麻烦问一下,如何设置打断距离
发表于 2011-11-23 12:17 | 显示全部楼层
多谢楼主分享源码
发表于 2011-11-23 12:24 | 显示全部楼层
多谢楼主分享
发表于 2011-11-23 12:38 | 显示全部楼层
2012 x64运行不能正确打断
发表于 2011-11-23 19:09 | 显示全部楼层
求得交点重画线段应该会简单点吧!

点评

直线应该是简单,但如果是弧或者其他曲线呢?请讲讲具体的方法,谢谢  发表于 2011-11-23 19:18
发表于 2011-11-23 19:39 | 显示全部楼层
本帖最后由 cjrun 于 2011-11-23 20:52 编辑
cjrun 发表于 2011-11-23 19:09
求得交点重画线段应该会简单点吧!
你是对的,很多曲线不能重画!

发表于 2011-11-23 20:37 | 显示全部楼层
又测试了一下
自身打断不能实现

我很需要这样一个程序
楼主重新完善一下吧
 楼主| 发表于 2011-11-24 23:55 | 显示全部楼层
本帖最后由 yjr111 于 2011-11-25 00:04 编辑

打断竟然比想象中难好多,要怎么样才能打断充分呢?经过2天苦思冥想,多次测试,也许下面的程序能给你个答案!(请勿踢我

程序一楼更新。。。。。。

发表于 2011-11-25 08:08 | 显示全部楼层
本帖最后由 x_s_s_1 于 2011-11-25 08:11 编辑


lee mac的圆打断,希望对您有启发


  1. ;;--------------------=={ Circle Break }==--------------------;;
  2. ;;                                                            ;;
  3. ;;  Breaks a circle into two arcs and places the arc created  ;;
  4. ;;  from the portion of the circle selected on designated     ;;
  5. ;;  layer.                                                    ;;
  6. ;;------------------------------------------------------------;;
  7. ;;  Author: Lee Mac, Copyright ?2011 - www.lee-mac.com       ;;
  8. ;;------------------------------------------------------------;;

  9. (defun c:cbrk

  10.   ( / *error* _StartUndo _EndUndo LM:Permute LM:Clockwise-p LM:RemovePairs
  11.       acdoc c cn el hiddenlayer norm p1 p2 ra xang
  12.   )

  13. ;;------------------------------------------------------------;;

  14.   (setq HiddenLayer "1") ;; Name of Hidden Layer

  15. ;;------------------------------------------------------------;;

  16.   (defun *error* ( msg )
  17.     (if acdoc (_EndUndo acdoc))
  18.     (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  19.         (princ (strcat "\n** Error: " msg " **")))
  20.     (princ)
  21.   )

  22.   (defun _StartUndo ( doc ) (_EndUndo doc)
  23.     (vla-StartUndoMark doc)
  24.   )

  25.   (defun _EndUndo ( doc )
  26.     (if (= 8 (logand 8 (getvar 'UNDOCTL)))
  27.       (vla-EndUndoMark doc)
  28.     )
  29.   )

  30.   (defun LM:Permute ( a b / c )
  31.     (setq c (eval a)) (set a (eval b)) (set b c)
  32.   )

  33.   (defun LM:Clockwise-p ( p1 p2 p3 )
  34.     ( (lambda ( n ) (< (car (trans p2 0 n)) (car (trans p1 0 n)))) (mapcar '- p1 p3))
  35.   )

  36.   (defun LM:RemovePairs ( lst pairs )
  37.     (vl-remove-if '(lambda ( pair ) (member (car pair) pairs)) lst)
  38.   )

  39. ;;------------------------------------------------------------;;

  40.   (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  41.   
  42.   (or (tblsearch "LAYER" HiddenLayer)
  43.       (vla-add (vla-get-layers acdoc) HiddenLayer)
  44.   )

  45.   (if
  46.     (and
  47.       (setq c
  48.         (LM:Selectif "\nSelect Circle: "
  49.          '(lambda ( x ) (eq "CIRCLE" (cdr (assoc 0 (entget (car x)))))) entsel nil
  50.         )
  51.       )
  52.       (setq p1 (getpoint "\nSelect First Break Point: "))
  53.       (progn
  54.         (while (equal p1 (setq p2 (getpoint "\nSelect Second Break Point: ")) 1e-6)
  55.           (princ "\n** Points must be distinct **")
  56.         )
  57.         p2
  58.       )
  59.     )
  60.     (progn
  61.       (_StartUndo acdoc)
  62.       
  63.       (setq norm (trans '(0. 0. 1.) 1 0 t)
  64.             xAng (angle '(0. 0. 0.) (trans (getvar 'UCSXDIR) 0 norm t)))
  65.       
  66.       (setq p1 (trans (vlax-curve-getClosestPointto (car c) (trans p1 1 0)) 0 norm)
  67.             p2 (trans (vlax-curve-getClosestPointto (car c) (trans p2 1 0)) 0 norm)
  68.             cn (cdr (assoc 10 (setq el (entget (car c)))))
  69.             ra (cdr (assoc 40 el))
  70.       )
  71.       (if (< (- (angle cn p1) xAng) (- (angle cn p2) xAng))
  72.         (LM:Permute 'p1 'p2)
  73.       )
  74.       (
  75.         (lambda ( a1 a2 )
  76.           (mapcar
  77.             (function
  78.               (lambda ( la s e )
  79.                 (entmake
  80.                   (append (list (cons 0 "ARC") (cons 8 la) (cons 50 s) (cons 51 e))
  81.                     (LM:RemovePairs el '(0 5 8 100))
  82.                   )
  83.                 )
  84.               )
  85.             )
  86.             (if (LM:Clockwise-p p1 (trans (cadr c) 1 norm) p2)
  87.               (list (cdr (assoc 8 el)) HiddenLayer)
  88.               (list HiddenLayer (cdr (assoc 8 el)))
  89.             )
  90.             (list a1 a2)
  91.             (list a2 a1)
  92.           )
  93.         )
  94.         (angle cn p1) (angle cn p2)
  95.       )
  96.       (entdel (car c))

  97.       (_EndUndo acdoc)
  98.     )
  99.   )
  100.   (princ)
  101. )

  102. ;;---------------------=={ Select if }==----------------------;;
  103. ;;                                                            ;;
  104. ;;  Provides continuous selection prompts until either a      ;;
  105. ;;  predicate function is validated or a keyword is supplied. ;;
  106. ;;------------------------------------------------------------;;
  107. ;;  Author: Lee Mac, Copyright ?2011 - www.lee-mac.com       ;;
  108. ;;------------------------------------------------------------;;
  109. ;;  Arguments:                                                ;;
  110. ;;  msg  - prompt string                                      ;;
  111. ;;  pred - optional predicate function [selection list arg]   ;;
  112. ;;  func - selection function to invoke                       ;;
  113. ;;  keyw - optional initget argument list                     ;;
  114. ;;------------------------------------------------------------;;
  115. ;;  Returns:  Entity selection list, keyword, or nil          ;;
  116. ;;------------------------------------------------------------;;

  117. (defun LM:SelectIf ( msg pred func keyw / sel ) (setq pred (eval pred))  
  118.   (while
  119.     (progn (setvar 'ERRNO 0) (if keyw (apply 'initget keyw)) (setq sel (func msg))
  120.       (cond
  121.         ( (= 7 (getvar 'ERRNO))
  122.           (princ "\nMissed, Try again.")
  123.         )
  124.         ( (eq 'STR (type sel))
  125.           nil
  126.         )
  127.         ( (vl-consp sel)
  128.           (if (and pred (not (pred sel)))
  129.             (princ "\nInvalid Object Selected.")
  130.           )
  131.         )
  132.       )
  133.     )
  134.   )
  135.   sel
  136. )

  137. (vl-load-com) (princ)

  138. ;;------------------------------------------------------------;;
  139. ;;                         End of File                        ;;
  140. ;;------------------------------------------------------------;;
发表于 2011-11-25 08:36 | 显示全部楼层
本帖最后由 x_s_s_1 于 2011-11-25 08:52 编辑

不知为何不能直接回复您的帖子,还有图片贴不出来,很佩服您的学习精神,可惜我没有多余时间,搞结构都比较忙,我一般是拿来主义,局部自己会改一些就行了,以后还请您多指教。搜到一个Charles Alan Butler 的程序,希望也对您有启发。
达到您的效果可用BreakObject命令
有对话框的
  1. ;;;=======================[ BreakObjects.lsp ]==============================
  2. ;;; Author: Copyright?2006-2008 Charles Alan Butler
  3. ;;; Contact @  www.TheSwamp.org
  4. ;;; Version:  2.1  Nov. 20,2008
  5. ;;; Purpose: Break All selected objects
  6. ;;;    permitted objects are lines, lwplines, plines, splines,
  7. ;;;    ellipse, circles & arcs
  8. ;;;                           
  9. ;;;  Function  c:MyBreak -       DCL for selecting the routines
  10. ;;;  Function  c:BreakAll -      Break all objects selected with each other
  11. ;;;  Function  c:BreakwObject  - Break many objects with a single object
  12. ;;;  Function  c:BreakObject -   Break a single object with other objects
  13. ;;;  Function  c:BreakWith -     Break selected objects with other selected objects
  14. ;;;  Function  c:BreakTouching - Break objects touching selected objects
  15. ;;;  Function  c:BreakSelected - Break selected objects with any objects that touch it
  16. ;;;  Revision 1.8 Added Option for Break Gap greater than zero
  17. ;;;  NEW r1.9  c:BreakWlayer -   Break objects with objects on a layer
  18. ;;;  NEW r1.9  c:BreakWithTouching - Break touching objects with selected objects
  19. ;;;  Revision 2.0 Fixed a bug when point to break is at the end of object
  20. ;;;  Revision 2.1 Fixed another bug when point to break is at the end of object
  21. ;;;
  22. ;;;
  23. ;;;  Function  break_with  - main break function called by all others and
  24. ;;;                          returns a list of new enames, see c:BreakAll
  25. ;;;                          for an example of using the return list
  26. ;;;
  27. ;;; Requirements: objects must have the same z-value
  28. ;;; Restrictions: Does not Break objects on locked layers
  29. ;;; Returns:  none
  30. ;;;
  31. ;;;=====================================================================
  32. ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED     ;
  33. ;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR  ;
  34. ;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.            ;
  35. ;;;                                                                    ;
  36. ;;;  You are hereby granted permission to use, copy and modify this    ;
  37. ;;;  software without charge, provided you do so exclusively for       ;
  38. ;;;  your own use or for use by others in your organization in the     ;
  39. ;;;  performance of their normal duties, and provided further that     ;
  40. ;;;  the above copyright notice appears in all copies and both that    ;
  41. ;;;  copyright notice and the limited warranty and restricted rights   ;
  42. ;;;  notice below appear in all supporting documentation.              ;
  43. ;;;=====================================================================


  44. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  45. ;;               M A I N   S U B R O U T I N E                  
  46. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  47. (defun break_with (ss2brk ss2brkwith self Gap / cmd intpts lst masterlist ss ssobjs
  48.                    onlockedlayer ssget->vla-list list->3pair GetNewEntities oc
  49.                    get_interpts break_obj GetLastEnt LastEntInDatabase ss2brkwithList
  50.                   )
  51.   ;; ss2brk     selection set to break
  52.   ;; ss2brkwith selection set to use as break points
  53.   ;; self       when true will allow an object to break itself
  54.   ;;            note that plined will break at each vertex
  55.   ;;
  56.   ;; return list of enames of new objects
  57.   
  58.   (vl-load-com)
  59.   
  60.   (princ "\nCalculating Break Points, Please Wait.\n")

  61. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  62. ;;                S U B   F U N C T I O N S                     
  63. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  64.   ;;  return T if entity is on a locked layer
  65.   (defun onlockedlayer (ename / entlst)
  66.     (setq entlst (tblsearch "LAYER" (cdr (assoc 8 (entget ename)))))
  67.     (= 4 (logand 4 (cdr (assoc 70 entlst))))
  68.   )

  69.   ;;  return a list of objects from a selection set
  70. ;|  (defun ssget->vla-list (ss)
  71.     (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss ))))
  72.   )|;
  73.   (defun ssget->vla-list (ss / i ename allobj) ; this is faster, changed in ver 1.7
  74.        (setq i -1)
  75.        (while (setq  ename (ssname ss (setq i (1+ i))))
  76.          (setq allobj (cons (vlax-ename->vla-object ename) allobj))
  77.        )
  78.        allobj
  79.   )
  80.   
  81.   ;;  return a list of lists grouped by 3 from a flat list
  82.   (defun list->3pair (old / new)
  83.     (while (setq new (cons (list (car old) (cadr old) (caddr old)) new)
  84.                  old (cdddr old)))
  85.     (reverse new)
  86.   )
  87.   
  88. ;;=====================================
  89. ;;  return a list of intersect points  
  90. ;;=====================================
  91. (defun get_interpts (obj1 obj2 / iplist)
  92.   (if (not (vl-catch-all-error-p
  93.              (setq iplist (vl-catch-all-apply
  94.                             'vlax-safearray->list
  95.                             (list
  96.                               (vlax-variant-value
  97.                                 (vla-intersectwith obj1 obj2 acextendnone)
  98.                               ))))))
  99.     iplist
  100.   )
  101. )


  102. ;;========================================
  103. ;;  Break entity at break points in list  
  104. ;;========================================
  105. ;;   New as per version 1.8 [BrkGap] --- This subroutine has been re-written
  106. ;;  Loop through the break points breaking the entity
  107. ;;  If the entity is not a closed entity then a new object is created
  108. ;;  This object is added to a list. When break points don't fall on the current
  109. ;;  entity the list of new entities are searched to locate the entity that the
  110. ;;  point is on so it can be broken.
  111. ;;  "Break with a Gap" has been added to this routine. The problem faced with
  112. ;;  this method is that sections to be removed may lap if the break points are
  113. ;;  too close to each other. The solution is to create a list of break point pairs
  114. ;;  representing the gap to be removed and test to see if there i an overlap. If
  115. ;;  there is then merge the break point pairs into one large gap. This way the
  116. ;;  points will always fall on an object with one exception. If the gap is too near
  117. ;;  the end of an object one break point will be off the end and therefore that
  118. ;;  point will need to be replaced with the end point.
  119. ;;    NOTE: in ACAD2000 the (vlax-curve-getdistatpoint function has proven unreliable
  120. ;;  so I have used (vlax-curve-getdistatparam in most cases
  121. (defun break_obj (ent brkptlst BrkGap / brkobjlst en enttype maxparam closedobj
  122.                   minparam obj obj2break p1param p2param brkpt2 dlst idx brkptS
  123.                   brkptE brkpt result GapFlg result ignore dist tmppt
  124.                   #ofpts 2gap enddist lastent obj2break stdist
  125.                  )
  126.   (or BrkGap (setq BrkGap 0.0)) ; default to 0
  127.   (setq BrkGap (/ BrkGap 2.0)) ; if Gap use 1/2 per side of break point
  128.   
  129.   (setq obj2break ent
  130.         brkobjlst (list ent)
  131.         enttype   (cdr (assoc 0 (entget ent)))
  132.         GapFlg    (not (zerop BrkGap)) ; gap > 0
  133.         closedobj (vlax-curve-isclosed obj2break)
  134.   )
  135.   ;; when zero gap no need to break at end points
  136.   (if (zerop Brkgap)
  137.     (setq spt (vlax-curve-getstartpoint ent)
  138.           ept (vlax-curve-getendpoint ent)
  139.           brkptlst (vl-remove-if '(lambda(x) (or (< (distance x spt) 0.0001)
  140.                                                  (< (distance x ept) 0.0001)))
  141.                                  brkptlst)
  142.     )
  143.   )
  144.   (if brkptlst
  145.     (progn
  146.   ;;  sort break points based on the distance along the break object
  147.   ;;  get distance to break point, catch error if pt is off end
  148.   ;; ver 2.0 fix - added COND to fix break point is at the end of a
  149.   ;; line which is not a valid break but does no harm
  150.   (setq brkptlst (mapcar '(lambda(x) (list x (vlax-curve-getdistatparam obj2break
  151.                                                ;; ver 2.0 fix
  152.                                                (cond ((vlax-curve-getparamatpoint obj2break x))
  153.                                                    ((vlax-curve-getparamatpoint obj2break
  154.                                                      (vlax-curve-getclosestpointto obj2break x))))))
  155.                             ) brkptlst))
  156.   ;; sort primary list on distance
  157.   (setq brkptlst (vl-sort brkptlst '(lambda (a1 a2) (< (cadr a1) (cadr a2)))))
  158.   
  159.   (if GapFlg ; gap > 0
  160.     ;; Brkptlst starts as the break point and then a list of pairs of points
  161.     ;;  is creates as the break points
  162.     (progn
  163.       ;;  create a list of list of break points
  164.       ;;  ((idx# stpoint distance)(idx# endpoint distance)...)
  165.       (setq idx 0)
  166.       (foreach brkpt brkptlst
  167.         
  168.         ;; ----------------------------------------------------------
  169.         ;;  create start break point, then create end break point   
  170.         ;;  ((idx# startpoint distance)(idx# endpoint distance)...)  
  171.         ;; ----------------------------------------------------------
  172.         (setq dist (cadr brkpt)) ; distance to center of gap
  173.         ;;  subtract gap to get start point of break gap
  174.         (cond
  175.           ((and (minusp (setq stDist (- dist BrkGap))) closedobj )
  176.            (setq stdist (+ (vlax-curve-getdistatparam obj2break
  177.                              (vlax-curve-getendparam obj2break)) stDist))
  178.            (setq dlst (cons (list idx
  179.                                   (vlax-curve-getpointatparam obj2break
  180.                                          (vlax-curve-getparamatdist obj2break stDist))
  181.                                   stDist) dlst))
  182.            )
  183.           ((minusp stDist) ; off start of object so get startpoint
  184.            (setq dlst (cons (list idx (vlax-curve-getstartpoint obj2break) 0.0) dlst))
  185.            )
  186.           (t
  187.            (setq dlst (cons (list idx
  188.                                   (vlax-curve-getpointatparam obj2break
  189.                                          (vlax-curve-getparamatdist obj2break stDist))
  190.                                   stDist) dlst))
  191.           )
  192.         )
  193.         ;;  add gap to get end point of break gap
  194.         (cond
  195.           ((and (> (setq stDist (+ dist BrkGap))
  196.                    (setq endDist (vlax-curve-getdistatparam obj2break
  197.                                      (vlax-curve-getendparam obj2break)))) closedobj )
  198.            (setq stdist (- stDist endDist))
  199.            (setq dlst (cons (list idx
  200.                                   (vlax-curve-getpointatparam obj2break
  201.                                          (vlax-curve-getparamatdist obj2break stDist))
  202.                                   stDist) dlst))
  203.            )
  204.           ((> stDist endDist) ; off end of object so get endpoint
  205.            (setq dlst (cons (list idx
  206.                                   (vlax-curve-getpointatparam obj2break
  207.                                         (vlax-curve-getendparam obj2break))
  208.                                   endDist) dlst))
  209.            )
  210.           (t
  211.            (setq dlst (cons (list idx
  212.                                   (vlax-curve-getpointatparam obj2break
  213.                                          (vlax-curve-getparamatdist obj2break stDist))
  214.                                   stDist) dlst))
  215.           )
  216.         )
  217.         ;; -------------------------------------------------------
  218.         (setq idx (1+ IDX))
  219.       ) ; foreach brkpt brkptlst
  220.       

  221.       (setq dlst (reverse dlst))
  222.       ;;  remove the points of the gap segments that overlap
  223.       (setq idx -1
  224.             2gap (* BrkGap 2)
  225.             #ofPts (length Brkptlst)
  226.       )
  227.       (while (<= (setq idx (1+ idx)) #ofPts)
  228.         (cond
  229.           ((null result) ; 1st time through
  230.            (setq result (list (car dlst)) ; get first start point
  231.                  result (cons (nth (1+(* idx 2)) dlst) result))
  232.           )
  233.           ((= idx #ofPts) ; last pass, check for wrap
  234.            (if (and closedobj (> #ofPts 1)
  235.                     (<= (+(- (vlax-curve-getdistatparam obj2break
  236.                             (vlax-curve-getendparam obj2break))
  237.                           (cadr (last BrkPtLst))) (cadar BrkPtLst)) 2Gap))
  238.              (progn
  239.                (if (zerop (rem (length result) 2))
  240.                  (setq result (cdr result)) ; remove the last end point
  241.                )
  242.                ;;  ignore previous endpoint and present start point
  243.                (setq result (cons (cadr (reverse result)) result) ; get last end point
  244.                      result (cdr (reverse result))
  245.                      result (reverse (cdr result)))
  246.              )
  247.            )
  248.           )
  249.           ;; Break Gap Overlaps
  250.           ((< (cadr (nth idx Brkptlst)) (+ (cadr (nth (1- idx) Brkptlst)) 2Gap))
  251.            (if (zerop (rem (length result) 2))
  252.              (setq result (cdr result)) ; remove the last end point
  253.            )
  254.            ;;  ignore previous endpoint and present start point
  255.            (setq result (cons (nth (1+(* idx 2)) dlst) result)) ; get present end point
  256.            )
  257.           ;; Break Gap does Not Overlap previous point
  258.           (t
  259.            (setq result (cons (nth (* idx 2) dlst) result)) ; get this start point
  260.            (setq result (cons (nth (1+(* idx 2)) dlst) result)) ; get this end point
  261.           )
  262.         ) ; end cond stmt
  263.       ) ; while
  264.       
  265.       ;;  setup brkptlst with pair of break pts ((p1 p2)(p3 p4)...)
  266.       ;;  one of the pair of points will be on the object that
  267.       ;;  needs to be broken
  268.       (setq dlst     (reverse result)
  269.             brkptlst nil)
  270.       (while dlst ; grab the points only
  271.         (setq brkptlst (cons (list (cadar dlst)(cadadr dlst)) brkptlst)
  272.               dlst   (cddr dlst))
  273.       )
  274.     )
  275.   )
  276.   ;;   -----------------------------------------------------

  277.   ;; (if (equal  a ent) (princ)) ; debug CAB  -------------

  278.   (foreach brkpt (reverse brkptlst)
  279.     (if GapFlg ; gap > 0
  280.       (setq brkptS (car brkpt)
  281.             brkptE (cadr brkpt))
  282.       (setq brkptS (car brkpt)
  283.             brkptE brkptS)
  284.     )
  285.     ;;  get last entity created via break in case multiple breaks
  286.     (if brkobjlst
  287.       (progn
  288.         (setq tmppt brkptS) ; use only one of the pair of breakpoints
  289.         ;;  if pt not on object x, switch objects
  290.         (if (not (numberp (vl-catch-all-apply
  291.                             'vlax-curve-getdistatpoint (list obj2break tmppt))))
  292.           (progn ; find the one that pt is on
  293.             (setq idx (length brkobjlst))
  294.             (while (and (not (minusp (setq idx (1- idx))))
  295.                         (setq obj (nth idx brkobjlst))
  296.                         (if (numberp (vl-catch-all-apply
  297.                                        'vlax-curve-getdistatpoint (list obj tmppt)))
  298.                           (null (setq obj2break obj)) ; switch objects, null causes exit
  299.                           t
  300.                         )
  301.                    )
  302.             )
  303.           )
  304.         )
  305.       )
  306.     )
  307.     ;| ;; ver 2.0 fix - removed this code as there are cases where the break point
  308.        ;; is at the end of a line which is not a valid break but does no harm
  309.     (if (and brkobjlst idx (minusp idx)
  310.              (null (alert (strcat "Error - point not on object"
  311.                                   "\nPlease report this error to"
  312.                                   "\n   CAB at TheSwamp.org"))))
  313.       (exit)
  314.     )
  315.     |;
  316.     ;; (if (equal (if (null a)(setq a (car(entsel"\nTest Ent"))) a) ent) (princ)) ; debug CAB  -------------

  317.     ;;  Handle any objects that can not be used with the Break Command
  318.     ;;  using one point, gap of 0.000001 is used
  319.     (setq closedobj (vlax-curve-isclosed obj2break))
  320.     (if GapFlg ; gap > 0
  321.       (if closedobj
  322.         (progn ; need to break a closed object
  323.           (setq brkpt2 (vlax-curve-getPointAtDist obj2break
  324.                      (- (vlax-curve-getDistAtPoint obj2break brkptE) 0.00001)))
  325.           (command "._break" obj2break "_non" (trans brkpt2 0 1)
  326.                    "_non" (trans brkptE 0 1))
  327.           (and (= "CIRCLE" enttype) (setq enttype "ARC"))
  328.           (setq BrkptE brkpt2)
  329.         )
  330.       )
  331.       ;;  single breakpoint ----------------------------------------------------
  332.       ;|(if (and closedobj ; problems with ACAD200 & this code
  333.                (not (setq brkptE (vlax-curve-getPointAtDist obj2break
  334.                        (+ (vlax-curve-getDistAtPoint obj2break brkptS) 0.00001))))
  335.           )
  336.         (setq brkptE (vlax-curve-getPointAtDist obj2break
  337.                        (- (vlax-curve-getDistAtPoint obj2break brkptS) 0.00001)))
  338.         
  339.       )|;
  340.       (if (and closedobj
  341.                (not (setq brkptE (vlax-curve-getPointAtDist obj2break
  342.                        (+ (vlax-curve-getdistatparam obj2break
  343.                             ;;(vlax-curve-getparamatpoint obj2break brkpts)) 0.00001))))
  344.                             ;; ver 2.0 fix
  345.                             (cond ((vlax-curve-getparamatpoint obj2break brkpts))
  346.                                   ((vlax-curve-getparamatpoint obj2break
  347.                                       (vlax-curve-getclosestpointto obj2break brkpts))))) 0.00001)))))
  348.         (setq brkptE (vlax-curve-getPointAtDist obj2break
  349.                        (- (vlax-curve-getdistatparam obj2break
  350.                             ;;(vlax-curve-getparamatpoint obj2break brkpts)) 0.00001)))
  351.                             ;; ver 2.0 fix
  352.                             (cond ((vlax-curve-getparamatpoint obj2break brkpts))
  353.                                   ((vlax-curve-getparamatpoint obj2break
  354.                                       (vlax-curve-getclosestpointto obj2break brkpts))))) 0.00001)))
  355.        )
  356.     ) ; endif
  357.    
  358.     ;; (if (null brkptE) (princ)) ; debug
  359.    
  360.     (setq LastEnt (GetLastEnt))
  361.     (command "._break" obj2break "_non" (trans brkptS 0 1) "_non" (trans brkptE 0 1))
  362.     (and *BrkVerbose* (princ (setq *brkcnt* (1+ *brkcnt*))) (princ "\r"))
  363.     (and (= "CIRCLE" enttype) (setq enttype "ARC"))
  364.     (if (and (not closedobj) ; new object was created
  365.              (not (equal LastEnt (entlast))))
  366.         (setq brkobjlst (cons (entlast) brkobjlst))
  367.     )
  368.   )
  369.   )
  370.   ) ; endif brkptlst
  371.   
  372. ) ; defun break_obj

  373. ;;====================================
  374. ;;  CAB - get last entity in datatbase
  375. (defun GetLastEnt ( / ename result )
  376.   (if (setq result (entlast))
  377.     (while (setq ename (entnext result))
  378.       (setq result ename)
  379.     )
  380.   )
  381.   result
  382. )
  383. ;;===================================
  384. ;;  CAB - return a list of new enames
  385. (defun GetNewEntities (ename / new)
  386.   (cond
  387.     ((null ename) (alert "Ename nil"))
  388.     ((eq 'ENAME (type ename))
  389.       (while (setq ename (entnext ename))
  390.         (if (entget ename) (setq new (cons ename new)))
  391.       )
  392.     )
  393.     ((alert "Ename wrong type."))
  394.   )
  395.   new
  396. )

  397.   
  398.   ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  399.   ;;         S T A R T  S U B R O U T I N E   H E R E              
  400.   ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  401.    
  402.     (setq LastEntInDatabase (GetLastEnt))
  403.     (if (and ss2brk ss2brkwith)
  404.     (progn
  405.       (setq oc 0
  406.             ss2brkwithList (ssget->vla-list ss2brkwith))
  407.       (if (> (* (sslength ss2brk)(length ss2brkwithList)) 5000)
  408.         (setq *BrkVerbose* t)
  409.       )
  410.       (and *BrkVerbose*
  411.            (princ (strcat "Objects to be Checked: "
  412.             (itoa (* (sslength ss2brk)(length ss2brkwithList))) "\n")))
  413.       ;;  CREATE a list of entity & it's break points
  414.       (foreach obj (ssget->vla-list ss2brk) ; check each object in ss2brk
  415.         (if (not (onlockedlayer (vlax-vla-object->ename obj)))
  416.           (progn
  417.             (setq lst nil)
  418.             ;; check for break pts with other objects in ss2brkwith
  419.             (foreach intobj  ss2brkwithList
  420.               (if (and (or self (not (equal obj intobj)))
  421.                        (setq intpts (get_interpts obj intobj))
  422.                   )
  423.                 (setq lst (append (list->3pair intpts) lst)) ; entity w/ break points
  424.               )
  425.               (and *BrkVerbose* (princ (strcat "Objects Checked: " (itoa (setq oc (1+ oc))) "\r")))
  426.             )
  427.             (if lst
  428.               (setq masterlist (cons (cons (vlax-vla-object->ename obj) lst) masterlist))
  429.             )
  430.           )
  431.         )
  432.       )

  433.       
  434.       (and *BrkVerbose* (princ "\nBreaking Objects.\n"))
  435.       (setq *brkcnt* 0) ; break counter
  436.       ;;  masterlist = ((ent brkpts)(ent brkpts)...)
  437.       (if masterlist
  438.         (foreach obj2brk masterlist
  439.           (break_obj (car obj2brk) (cdr obj2brk) Gap)
  440.         )
  441.       )
  442.       )
  443.   )
  444. ;;==============================================================
  445.    (and (zerop *brkcnt*) (princ "\nNone to be broken."))
  446.    (setq *BrkVerbose* nil)
  447.   (GetNewEntities LastEntInDatabase) ; return list of enames of new objects
  448. )
  449. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  450. ;;      E N D   O F    M A I N   S U B R O U T I N E            
  451. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


  452. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  453. ;;           M A I N   S U B   F U N C T I O N S                 
  454. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  455.   ;;======================
  456.   ;;  Redraw ss with mode
  457.   ;;======================
  458.   (defun ssredraw (ss mode / i num)
  459.     (setq i -1)
  460.     (while (setq ename (ssname ss (setq i (1+ i))))
  461.       (redraw (ssname ss i) mode)
  462.     )
  463.   )

  464.   ;;===========================================================================
  465.   ;;  get all objects touching entities in the sscross                        
  466.   ;;  limited obj types to "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"
  467.   ;;  returns a list of enames
  468.   ;;===========================================================================
  469.   (defun gettouching (sscros / ss lst lstb lstc objl)
  470.     (and
  471.       (setq lstb (vl-remove-if 'listp (mapcar 'cadr (ssnamex sscros)))
  472.             objl (mapcar 'vlax-ename->vla-object lstb)
  473.       )
  474.       (setq
  475.         ss (ssget "_A" (list (cons 0 "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE")
  476.                              (cons 410 (getvar "ctab"))))
  477.       )
  478.       (setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  479.       (setq lst (mapcar 'vlax-ename->vla-object lst))
  480.       (mapcar
  481.         '(lambda (x)
  482.            (mapcar
  483.              '(lambda (y)
  484.                 (if (not
  485.                       (vl-catch-all-error-p
  486.                         (vl-catch-all-apply
  487.                           '(lambda ()
  488.                              (vlax-safearray->list
  489.                                (vlax-variant-value
  490.                                  (vla-intersectwith y x acextendnone)
  491.                                ))))))
  492.                   (setq lstc (cons (vlax-vla-object->ename x) lstc))
  493.                 )
  494.               ) objl)
  495.          ) lst)
  496.     )
  497.     lstc
  498.   )



  499. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  500. ;;          E N D   M A I N    F U N C T I O N S                 
  501. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



  502. ;;===============================================
  503. ;;   Break all objects selected with each other  
  504. ;;===============================================
  505. (defun c:BreakAll (/ cmd ss NewEnts AllEnts tmp)

  506.   (command "_.undo" "_begin")
  507.   (setq cmd (getvar "CMDECHO"))
  508.   (setvar "CMDECHO" 0)
  509.   (or Bgap (setq Bgap 0)) ; default
  510.   (initget 4) ; no negative numbers
  511.   (if (setq tmp (getdist (strcat "\nEnter Break Gap.<"(rtos Bgap)"> ")))
  512.     (setq Bgap tmp)
  513.   )
  514.   ;;  get objects to break
  515.   (prompt "\nSelect objects to break with each other & press enter: ")
  516.   (if (setq ss (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  517.      (setq NewEnts (Break_with ss ss nil Bgap) ; ss2break ss2breakwith (flag nil = not to break with self)
  518.            ; AllEnts (append NewEnts (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
  519.            )
  520.   )
  521.   (setvar "CMDECHO" cmd)
  522.   (command "_.undo" "_end")
  523.   (princ)
  524. )


  525. ;;===========================================
  526. ;;  Break a single object with other objects
  527. ;;===========================================
  528. (defun c:BreakObject (/ cmd ss1 ss2 tmp)

  529.   (command "_.undo" "_begin")
  530.   (setq cmd (getvar "CMDECHO"))
  531.   (setvar "CMDECHO" 0)
  532.   (or Bgap (setq Bgap 0)) ; default
  533.   (initget 4) ; no negative numbers
  534.   (if (setq tmp (getdist (strcat "\nEnter Break Gap.<"(rtos Bgap)"> ")))
  535.     (setq Bgap tmp)
  536.   )

  537.   ;;  get objects to break
  538.   (prompt "\nSelect single object to break: ")
  539.   (if (and (setq ss1 (ssget "+.:E:S" '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  540.            (not (redraw (ssname ss1 0) 3))
  541.            (not (prompt "\n***  Select object(s) to break with & press enter:  ***"))
  542.            (setq ss2 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  543.            (not (redraw (ssname ss1 0) 4)))
  544.      (Break_with ss1 ss2 nil Bgap) ; ss2break ss2breakwith (flag nil = not to break with self)
  545.   )

  546.   (setvar "CMDECHO" cmd)
  547.   (command "_.undo" "_end")
  548.   (princ)
  549. )

  550. ;;==========================================
  551. ;;  Break many objects with a single object
  552. ;;==========================================
  553. (defun c:BreakWobject (/ cmd ss1 ss2 tmp)

  554.   (command "_.undo" "_begin")
  555.   (setq cmd (getvar "CMDECHO"))
  556.   (setvar "CMDECHO" 0)
  557.   (or Bgap (setq Bgap 0)) ; default
  558.   (initget 4) ; no negative numbers
  559.   (if (setq tmp (getdist (strcat "\nEnter Break Gap.<"(rtos Bgap)"> ")))
  560.     (setq Bgap tmp)
  561.   )
  562.   ;;  get objects to break
  563.   (prompt "\nSelect object(s) to break & press enter: ")
  564.   (if (and (setq ss1 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  565.            (not (ssredraw ss1 3))
  566.            (not (prompt "\n***  Select single object to break with:  ***"))
  567.            (setq ss2 (ssget "+.:E:S" '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  568.            (not (ssredraw ss1 4))
  569.       )
  570.     (break_with ss1 ss2 nil Bgap) ; ss1break ss2breakwith (flag nil = not to break with self)
  571.   )

  572.   (setvar "CMDECHO" cmd)
  573.   (command "_.undo" "_end")
  574.   (princ)
  575. )


  576. ;;==========================================
  577. ;;  Break objects with objects on a layer   
  578. ;;==========================================
  579. ;;  New 08/01/2008
  580. (defun c:BreakWlayer (/ cmd ss1 ss2 tmp lay)

  581.   (command "_.undo" "_begin")
  582.   (setq cmd (getvar "CMDECHO"))
  583.   (setvar "CMDECHO" 0)
  584.   (or Bgap (setq Bgap 0)) ; default
  585.   (initget 4) ; no negative numbers
  586.   (if (setq tmp (getdist (strcat "\nEnter Break Gap.<"(rtos Bgap)"> ")))
  587.     (setq Bgap tmp)
  588.   )
  589.   ;;  get objects to break
  590.   (prompt "\n***  Select single object for break layer:  ***")
  591.   
  592.   (if (and (setq ss2 (ssget "+.:E:S" '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  593.            (setq lay (assoc 8 (entget (ssname ss2 0))))
  594.            (setq ss2 (ssget "_X" (list
  595.                                    '(0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE")
  596.                                    lay (cons 410 (getvar "ctab")))))
  597.            (not (prompt "\nSelect object(s) to break & press enter: "))
  598.            (setq ss1 (ssget (list
  599.                               '(0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE")
  600.                               (cons 8 (strcat "~" (cdr lay))))))
  601.       )
  602.     (break_with ss1 ss2 nil Bgap) ; ss1break ss2breakwith (flag nil = not to break with self)
  603.   )

  604.   (setvar "CMDECHO" cmd)
  605.   (command "_.undo" "_end")
  606.   (princ)
  607. )


  608. ;;======================================================
  609. ;;  Break selected objects with other selected objects  
  610. ;;======================================================
  611. (defun c:BreakWith (/ cmd ss1 ss2 tmp)

  612.   (command "_.undo" "_begin")
  613.   (setq cmd (getvar "CMDECHO"))
  614.   (setvar "CMDECHO" 0)
  615.   (or Bgap (setq Bgap 0)) ; default
  616.   (initget 4) ; no negative numbers
  617.   (if (setq tmp (getdist (strcat "\nEnter Break Gap.<"(rtos Bgap)"> ")))
  618.     (setq Bgap tmp)
  619.   )
  620.   ;;  get objects to break
  621.   (prompt "\nBreak selected objects with other selected objects.")
  622.   (prompt "\nSelect object(s) to break & press enter: ")
  623.   (if (and (setq ss1 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  624.            (not (ssredraw ss1 3))
  625.            (not (prompt "\n***  Select object(s) to break with & press enter:  ***"))
  626.            (setq ss2 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  627.            (not (ssredraw ss1 4))
  628.       )
  629.     (break_with ss1 ss2 nil Bgap) ; ss1break ss2breakwith (flag nil = not to break with self)
  630.   )

  631.   (setvar "CMDECHO" cmd)
  632.   (command "_.undo" "_end")
  633.   (princ)
  634. )



  635. ;;=============================================
  636. ;;  Break objects touching selected objects   
  637. ;;=============================================

  638. (defun c:BreakTouching (/ cmd ss1 ss2 tmp)

  639.   (command "_.undo" "_begin")
  640.   (setq cmd (getvar "CMDECHO"))
  641.   (setvar "CMDECHO" 0)
  642.   (setq ss1 (ssadd))
  643.   (or Bgap (setq Bgap 0)) ; default
  644.   (initget 4) ; no negative numbers
  645.   (if (setq tmp (getdist (strcat "\nEnter Break Gap.<"(rtos Bgap)"> ")))
  646.     (setq Bgap tmp)
  647.   )
  648.   ;;  get objects to break
  649.   (prompt "\nBreak objects touching selected objects.")
  650.   (if (and (not (prompt "\nSelect object(s) to break & press enter: "))
  651.            (setq ss2 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  652.            (mapcar '(lambda (x) (ssadd x ss1)) (gettouching ss2))
  653.       )
  654.     (break_with ss1 ss2 nil Bgap) ; ss1break ss2breakwith (flag nil = not to break with self)
  655.   )

  656.   (setvar "CMDECHO" cmd)
  657.   (command "_.undo" "_end")
  658.   (princ)
  659. )



  660. ;;=================================================
  661. ;;  Break touching objects with selected objects   
  662. ;;=================================================
  663. ;;  New 08/01/2008
  664. (defun c:BreakWithTouching (/ cmd ss1 ss2 tmp)

  665.   (command "_.undo" "_begin")
  666.   (setq cmd (getvar "CMDECHO"))
  667.   (setvar "CMDECHO" 0)
  668.   (setq ss1 (ssadd))
  669.   (or Bgap (setq Bgap 0)) ; default
  670.   (initget 4) ; no negative numbers
  671.   (if (setq tmp (getdist (strcat "\nEnter Break Gap.<"(rtos Bgap)"> ")))
  672.     (setq Bgap tmp)
  673.   )

  674.   ;;  get objects to break
  675.   (prompt "\nBreak objects touching selected objects.")
  676.   (prompt "\nSelect object(s) to break with & press enter: ")
  677.   (if (and (setq ss2 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  678.            (setq tlst (gettouching ss2))
  679.       )
  680.     (progn
  681.       (setq tlst (vl-remove-if '(lambda (x)(ssmemb x ss2)) tlst)) ;  remove if in picked ss
  682.       (mapcar '(lambda (x) (ssadd x ss1)) tlst) ; convert to a selection set
  683.       (break_with ss1 ss2 nil Bgap) ; ss1break ss2breakwith (flag nil = not to break with self)
  684.     )
  685.   )

  686.   (setvar "CMDECHO" cmd)
  687.   (command "_.undo" "_end")
  688.   (princ)
  689. )


  690. ;;==========================================================
  691. ;;  Break selected objects with any objects that touch it   
  692. ;;==========================================================


  693. (defun c:BreakSelected (/ cmd ss1 ss2 tmp)
  694.   
  695.   (command "_.undo" "_begin")
  696.   (setq cmd (getvar "CMDECHO"))
  697.   (setvar "CMDECHO" 0)
  698.   (setq ss1 (ssadd))
  699.   (or Bgap (setq Bgap 0)) ; default
  700.   (initget 4) ; no negative numbers
  701.   (if (setq tmp (getdist (strcat "\nEnter Break Gap.<"(rtos Bgap)"> ")))
  702.     (setq Bgap tmp)
  703.   )
  704.   ;;  get objects to break
  705.   (prompt "\nBreak selected objects with any objects that touch it.")
  706.   (if (and (not (prompt "\nSelect object(s) to break with touching & press enter: "))
  707.            (setq ss2 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  708.            (mapcar '(lambda (x) (ssadd x ss1)) (gettouching ss2))
  709.       )
  710.     (break_with ss2 ss1 nil Bgap) ; ss2break ss1breakwith (flag nil = not to break with self)
  711.   )

  712.   (setvar "CMDECHO" cmd)
  713.   (command "_.undo" "_end")
  714.   (princ)
  715. )

  716. ;; ***************************************************
  717. ;;     Function to create a dcl support file if it   
  718. ;;       does not exist                              
  719. ;;     Usage : (create_dcl "file name")               
  720. ;;     Returns : T if successful else nil            
  721. ;; ***************************************************
  722. (defun create_Breakdcl (fname / acadfn dcl-rev-check)
  723.   ;;=======================================
  724.   ;;      check revision date Routine         
  725.   ;;=======================================
  726.   (defun dcl-rev-check (fn / rvdate ln lp)
  727.     ;;  revision flag must match exactly and must
  728.     ;;  begin with //
  729.     (setq rvflag "//  Revision Control 05/12/2008@14:11" )
  730.     (if (setq fn (findfile fn))
  731.       (progn ; check rev date
  732.         (setq lp 5) ; read 4 lines
  733.         (setq fn (open fn "r")) ; open file for reading
  734.         (while (> (setq lp (1- lp)) 0)
  735.           (setq ln (read-line fn)) ; get a line from file
  736.           (if (vl-string-search rvflag ln)
  737.             (setq lp 0)
  738.           )
  739.         )
  740.         (close fn) ; close the open file handle
  741.         (if (= lp -1)
  742.           nil ; no new dcl needed
  743.           t ; flag to create new file
  744.         )
  745.       )
  746.       t ; flag to create new file
  747.     )
  748.   )
  749.   (if (null(wcmatch (strcase fname) "*`.DCL"))
  750.     (setq fname (strcat fname ".DCL"))
  751.   )
  752.   (if (dcl-rev-check fname)
  753.     ;; create dcl file in same directory as ACAD.PAT  
  754.     (progn
  755.       (setq acadfn (findfile "ACAD.PAT")
  756.             fn (strcat (substr acadfn 1 (- (strlen acadfn) 8))fname)
  757.             fn (open fn "w")
  758.       )
  759.       (foreach x (list
  760.                    "// WARNING file will be recreated if you change the next line"
  761.                    rvflag
  762.                    "//BreakAll.DCL"
  763.                    "BreakDCL : dialog { label = "[ Break All or Some by CAB  v1.8 ]";"
  764.                    "  : text { label = "--=<  Select type of Break Function needed  >=--"; "
  765.                    "           key = "tm"; alignment = centered; fixed_width = true;}"
  766.                    "    spacer_1;"
  767.                    "    : button { key = "b1"; mnemonic = "T";  alignment = centered;"
  768.                    "               label = "Break all objects selected with each other";} "
  769.                    "    : button { key = "b2"; mnemonic = "T"; alignment = centered;"
  770.                    "               label = "Break selected objects with other selected objects";}"
  771.                    "    : button { key = "b3"; mnemonic = "T";  alignment = centered;"
  772.                    "               label = " Break selected objects with any  objects that touch it";}"
  773.                    "    spacer_1;"
  774.                    "  : row { spacer_0;"
  775.                    "    : edit_box {key = "gap" ; width = 8; mnemonic = "G"; label = "Gap"; fixed_width = true;}"
  776.                    "    : button { label = "Help"; key = "help"; mnemonic = "H"; fixed_width = true;} "
  777.                    "    cancel_button;"
  778.                    "    spacer_0;"
  779.                    "  }"
  780.                    "}"
  781.                   ) ; endlist
  782.         (princ x fn)
  783.         (write-line "" fn)
  784.       ) ; end foreach
  785.       (close fn)
  786.       (setq acadfn nil)
  787.       (alert (strcat "\nDCL file created, please restart the routine"
  788.                "\n again if an error occures."))
  789.       t ; return True, file created
  790.     )
  791.     t ; return True, file found
  792.   )
  793. ) ; end defun


  794. ;;==============================
  795. ;;     BreakAll Dialog Routine  
  796. ;;==============================
  797. (defun c:MyBreak(/ dclfile dcl# RunDCL BreakHelp cmd txt2num)
  798.    ;;  return number or nil
  799.   (defun txt2num (txt / num)
  800.     (if txt
  801.     (or (setq num (distof txt 5))
  802.         (setq num (distof txt 2))
  803.         (setq num (distof txt 1))
  804.         (setq num (distof txt 4))
  805.         (setq num (distof txt 3))
  806.     )
  807.     )
  808.     (if (numberp num)
  809.       num
  810.     )
  811.   )
  812.   (defun mydonedialog (flag)
  813.     (setq DCLgap (txt2num (get_tile "gap")))
  814.     (done_dialog flag)
  815.   )
  816.   (defun RunDCL (/ action)
  817.     (or DCLgap (setq DCLgap 0)) ; error trap value
  818.     (action_tile "b1" "(mydonedialog 1)")
  819.     (action_tile "b2" "(mydonedialog 2)")
  820.     (action_tile "b3" "(mydonedialog 3)")
  821.     (action_tile "gap" "(setq DCLgap (txt2num value$))")
  822.     (set_tile "gap" (rtos DCLgap))
  823.     (action_tile "help" "(BreakHelp)")
  824.     (action_tile "cancel" "(done_dialog 0)")
  825.     (setq action (start_dialog))
  826.     (or DCLgap (setq DCLgap 0)) ; error trap value
  827.     (setq DCLgap (max DCLgap 0)) ; nu negative numbers
  828.    
  829.     (cond
  830.       ((= action 1) ; BreakAll
  831.          (command "_.undo" "_begin")
  832.   ;;  get objects to break
  833.   (prompt "\nSelect objects to break with each other & press enter: ")
  834.   (if (setq ss (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  835.      (setq NewEnts (Break_with ss ss nil DCLgap) ; ss2break ss2breakwith (flag nil = not to break with self)
  836.            ; AllEnts (append NewEnts (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
  837.            )
  838.   )
  839.   (command "_.undo" "_end")
  840.   (princ)
  841.        )
  842.       
  843.       ((= action 2) ; BreakWith
  844.          ;;  get objects to break
  845.   (prompt "\nBreak selected objects with other selected objects.")
  846.   (prompt "\nSelect object(s) to break & press enter: ")
  847.   (if (and (setq ss1 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  848.            (not (ssredraw ss1 3))
  849.            (not (prompt "\n***  Select object(s) to break with & press enter:  ***"))
  850.            (setq ss2 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  851.            (not (ssredraw ss1 4))
  852.       )
  853.     (break_with ss1 ss2 nil DCLgap) ; ss1break ss2breakwith (flag nil = not to break with self)
  854.   )

  855.        )
  856.       ((= action 3) ; BreakSelected
  857.   (setq ss1 (ssadd))
  858.   ;;  get objects to break
  859.   (prompt "\nBreak selected objects with any objects that touch it.")
  860.   (if (and (not (prompt "\nSelect object(s) to break with touching & press enter: "))
  861.            (setq ss2 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  862.            (mapcar '(lambda (x) (ssadd x ss1)) (gettouching ss2))
  863.       )
  864.     (break_with ss2 ss1 nil DCLgap) ; ss2break ss1breakwith (flag nil = not to break with self)
  865.   )
  866.        )
  867.     )
  868.   )
  869.   (defun BreakHelp ()
  870.     (alert
  871.       (strcat
  872.         "BreakAll.lsp               (c) 2007-2008 Charles Alan Butler\n\n"
  873.         "This LISP routine will break objects based on the routine you select.\n"
  874.         "It will not break objects on locked layers and objects must have the same z-value.\n"
  875.         "Object types are limited to LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE\n"
  876.         "BreakAll -      Break all objects selected with each other\n"
  877.         "BreakwObject  - Break many objects with a single object\n"
  878.         "BreakObject -   Break a single object with many objects \n"
  879.         "BreakWith -     Break selected objects with other selected objects\n"
  880.         "BreakTouching - Break objects touching selected objects\n"
  881.         "BreakSelected - Break selected objects with any objects that touch it\n"
  882.         " The Gap distance is the total opening created.\n"
  883.         "You may run each routine by entering the function name at the command line.\n"
  884.         "For updates & comments contact Charles Alan Butler AKA CAB at TheSwamp.org.\n")
  885.     )
  886.   )
  887.   
  888.   ;;================================================================
  889.   ;;                    Start of Routine                           
  890.   ;;================================================================
  891.   (vl-load-com)
  892.   (setq cmd (getvar "CMDECHO"))
  893.   (setvar "CMDECHO" 0)
  894.   (setq dclfile "BreakAll.dcl")
  895.   (cond
  896.     ((not (create_Breakdcl dclfile))
  897.      (prompt (strcat "\nCannot create " dclfile "."))
  898.     )
  899.     ((< (setq dcl# (load_dialog dclfile)) 0)
  900.      (prompt (strcat "\nCannot load " dclfile "."))
  901.     )
  902.     ((not (new_dialog "BreakDCL" dcl#))
  903.      (prompt (strcat "\nProblem with " dclfile "."))
  904.     )
  905.     ((RunDCL))      ; No DCL problems: fire it up
  906.   )
  907.   (and cmd (setvar "CMDECHO" cmd))
  908.   (princ)
  909. )
  910. (prompt "Break routines loaded, Enter Mybreak to run.")
  911. (princ)
  912. ;;/'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\.
  913. ;;    E n d   O f   F i l e   I f   y o u   A r e   H e r e      
  914. ;;/'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\.



没对话框的

  1. ;;;=======================[ BreakObjects.lsp ]==============================
  2. ;;; Author: Copyright?2006,2007 Charles Alan Butler
  3. ;;; Contact @  www.TheSwamp.org
  4. ;;; Version:  1.3 April 9,2007
  5. ;;; Globalization by XANADU - www.xanadu.cz
  6. ;;; Purpose: Break All selected objects
  7. ;;;    permitted objects are lines, lwplines, plines, splines,
  8. ;;;    ellipse, circles & arcs
  9. ;;;                           
  10. ;;;  Function  c:BreakAll -      Break all objects selected
  11. ;;;  Function  c:BreakwObjects - Break many objects with a single object
  12. ;;;  Function  c:BreakObject -   Break a single object with many objects
  13. ;;;  Function  c:BreakWith -     Break selected objects with other selected objects
  14. ;;;  Function  c:BreakTouching - Break objects touching the single Break object
  15. ;;;  Function  c:BreakSelected - Break selected objects with any  objects that touch it
  16. ;;;                    
  17. ;;; Sub_Routines:      
  18. ;;;    break_with      
  19. ;;;    ssget->vla-list
  20. ;;;    list->3pair     
  21. ;;;    onlockedlayer   
  22. ;;;    get_interpts Return a list of intersect points
  23. ;;;    break_obj  Break entity at break points in list
  24. ;;; Requirements: objects must have the same z-value
  25. ;;; Restrictions: Does not Break objects on locked layers
  26. ;;; Returns:  none
  27. ;;;=====================================================================
  28. ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED     ;
  29. ;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR  ;
  30. ;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.            ;
  31. ;;;                                                                    ;
  32. ;;;  You are hereby granted permission to use, copy and modify this    ;
  33. ;;;  software without charge, provided you do so exclusively for       ;
  34. ;;;  your own use or for use by others in your organization in the     ;
  35. ;;;  performance of their normal duties, and provided further that     ;
  36. ;;;  the above copyright notice appears in all copies and both that    ;
  37. ;;;  copyright notice and the limited warranty and restricted rights   ;
  38. ;;;  notice below appear in all supporting documentation.              ;
  39. ;;;=====================================================================


  40. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  41. ;;               M A I N   S U B R O U T I N E                  
  42. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  43. (defun break_with (ss2brk ss2brkwith self / cmd intpts lst masterlist ss ssobjs
  44.                    onlockedlayer ssget->vla-list list->3pair
  45.                    get_interpts break_obj
  46.                   )
  47.   ;; ss2brk     selection set to break
  48.   ;; ss2brkwith selection set to use as break points
  49.   ;; self       when true will allow an object to break itself
  50.   ;;            note that plined will break at each vertex
  51.   (vl-load-com)


  52. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  53. ;;                S U B   F U N C T I O N S                     
  54. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  55.   (defun onlockedlayer (ename / entlst)
  56.     (setq entlst (tblsearch "LAYER" (cdr (assoc 8 (entget ename)))))
  57.     (= 4 (logand 4 (cdr (assoc 70 entlst))))
  58.   )
  59.   
  60.   (defun ssget->vla-list (ss / i ename lst)
  61.     (setq i -1)
  62.     (while (setq ename (ssname ss (setq i (1+ i))))
  63.       (setq lst (cons (vlax-ename->vla-object ename) lst))
  64.     )
  65.     lst
  66.   )

  67.   (defun list->3pair (old / new)
  68.     (while (setq new (cons (list (car old) (cadr old) (caddr old)) new)
  69.                  old (cdddr old))
  70.     )
  71.     (reverse new)
  72.   )
  73.   
  74. ;;==============================================================
  75. ;;  return a list of intersect points
  76. ;;==============================================================
  77. (defun get_interpts (obj1 obj2 / iplist)
  78.   (if (not (vl-catch-all-error-p
  79.              (setq iplist (vl-catch-all-apply
  80.                             'vlax-safearray->list
  81.                             (list
  82.                               (vlax-variant-value
  83.                                 (vla-intersectwith obj1 obj2 acextendnone)
  84.                               ))))))
  85.     iplist
  86.   )
  87. )


  88. ;;==============================================================
  89. ;;  Break entity at break points in list
  90. ;;==============================================================
  91. (defun break_obj (ent brkptlst / brkobjlst en enttype maxparam closedobj
  92.                   minparam obj obj2break p1param p2 p2param
  93.                  )

  94.   (setq obj2break ent
  95.         brkobjlst (list ent)
  96.         enttype   (cdr (assoc 0 (entget ent)))
  97.   )

  98.   (foreach brkpt brkptlst
  99.     ;;  get last entity created via break in case multiple breaks
  100.     (if brkobjlst
  101.       (progn
  102.         ;;  if pt not on object x, switch objects
  103.         (if (not (numberp (vl-catch-all-apply 'vlax-curve-getdistatpoint (list obj2break brkpt)))
  104.             )
  105.           (foreach obj brkobjlst ; find the one that pt is on
  106.             (if (numberp (vl-catch-all-apply 'vlax-curve-getdistatpoint (list obj brkpt)))
  107.               (setq obj2break obj) ; switch objects
  108.             )
  109.           )
  110.         )
  111.       )
  112.     )

  113.     ;;  Handle any objects that can not be used with the Break Command
  114.     ;;  using one point, gap of 0.000001 is used
  115.     (cond
  116.       ((and (= "SPLINE" enttype) ; only closed splines
  117.             (vlax-curve-isclosed obj2break))
  118.        (setq p1param (vlax-curve-getparamatpoint obj2break brkpt)
  119.              p2      (vlax-curve-getpointatparam obj2break (+ p1param 0.000001))
  120.        )
  121.        (command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans p2 0 1))
  122.       )
  123.       ((= "CIRCLE" enttype) ; break the circle
  124.        (setq p1param (vlax-curve-getparamatpoint obj2break brkpt)
  125.              p2      (vlax-curve-getpointatparam obj2break (+ p1param 0.000001))
  126.        )
  127.        (command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans p2 0 1))
  128.        (setq enttype "ARC")
  129.       )
  130.       ((and (= "ELLIPSE" enttype) ; only closed ellipse
  131.             (vlax-curve-isclosed obj2break))
  132.        ;;  Break the ellipse, code borrowed from Joe Burke  6/6/2005
  133.        (setq p1param  (vlax-curve-getparamatpoint obj2break brkpt)
  134.              p2param  (+ p1param 0.000001)
  135.              minparam (min p1param p2param)
  136.              maxparam (max p1param p2param)
  137.              obj      (vlax-ename->vla-object obj2break)
  138.        )
  139.        (vlax-put obj 'startparameter maxparam)
  140.        (vlax-put obj 'endparameter (+ minparam (* pi 2)))
  141.       )
  142.       
  143.       ;;==================================
  144.       (t  ;   Objects that can be broken     
  145.        (setq closedobj (vlax-curve-isclosed obj2break))
  146.        (command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans brkpt 0 1))
  147.        (if (not closedobj) ; new object was created
  148.            (setq brkobjlst (cons (entlast) brkobjlst))
  149.        )
  150.       )
  151.     )
  152.   )
  153. )


  154.   
  155.   ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  156.   ;;                   S T A R T   H E R E                        
  157.   ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  158.     (if (and ss2brk ss2brkwith)
  159.     (progn
  160.       ;;  CREATE a list of entity & it's break points
  161.       (foreach obj (ssget->vla-list ss2brk) ; check each object in ss2brk
  162.         (if (not (onlockedlayer (vlax-vla-object->ename obj)))
  163.           (progn
  164.             (setq lst nil)
  165.             ;; check for break pts with other objects in ss2brkwith
  166.             (foreach intobj (ssget->vla-list ss2brkwith)
  167.               (if (and (or self (not (equal obj intobj)))
  168.                        (setq intpts (get_interpts obj intobj))
  169.                   )
  170.                 (setq lst (append (list->3pair intpts) lst)) ; entity w/ break points
  171.               )
  172.             )
  173.             (if lst
  174.               (setq masterlist (cons (cons (vlax-vla-object->ename obj) lst) masterlist))
  175.             )
  176.           )
  177.         )
  178.       )
  179.       ;;  masterlist = ((ent brkpts)(ent brkpts)...)
  180.       (if masterlist
  181.         (foreach obj2brk masterlist
  182.           (break_obj (car obj2brk) (cdr obj2brk))
  183.         )
  184.       )
  185.       )
  186.   )
  187. ;;==============================================================

  188. )
  189. (prompt "\nBreak Routines Loaded, Enter BreakAll, BreakEnt, or BreakWith to run.")
  190. (princ)



  191. ;;==========================================
  192. ;;        Break all objects selected        
  193. ;;==========================================
  194. (defun c:breakall (/ cmd ss)

  195.   (command "._undo" "_begin")
  196.   (setq cmd (getvar "CMDECHO"))
  197.   (setvar "CMDECHO" 0)

  198.   ;;  get objects to break
  199.   (prompt "\nSelect All objects to break & press enter: ")
  200.   (if (setq ss (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  201.      (Break_with ss ss nil) ; ss2break ss2breakwith (flag nil = not to break with self)
  202.   )

  203.   (setvar "CMDECHO" cmd)
  204.   (command "._undo" "_end")
  205.   (princ)
  206. )


  207. ;;==========================================
  208. ;;  Break a single object with many objects
  209. ;;==========================================
  210. (defun c:BreakObject (/ cmd ss1 ss2)

  211.   (command "._undo" "_begin")
  212.   (setq cmd (getvar "CMDECHO"))
  213.   (setvar "CMDECHO" 0)

  214.   ;;  get objects to break
  215.   (prompt "\nSelect single object to break: ")
  216.   (if (and (setq ss1 (ssget "+.:E:S" '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  217.            (not (redraw (ssname ss1 0) 3))
  218.            (not (prompt "\n***  Select object(s) to break with & press enter:  ***"))
  219.            (setq ss2 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  220.            (not (redraw (ssname ss1 0) 4)))
  221.      (Break_with ss1 ss2 nil) ; ss2break ss2breakwith (flag nil = not to break with self)
  222.   )

  223.   (setvar "CMDECHO" cmd)
  224.   (command "._undo" "_end")
  225.   (princ)
  226. )

  227. ;;==========================================
  228. ;;  Break many objects with a single object
  229. ;;==========================================
  230. (defun c:breakwobjects (/ cmd ss1 ss2)
  231.   (defun ssredraw (ss mode / i num)
  232.     (setq i -1)
  233.     (while (setq ename (ssname ss (setq i (1+ i))))
  234.       (redraw (ssname ss i) mode)
  235.     )
  236.   )
  237.   (command "._undo" "_begin")
  238.   (setq cmd (getvar "CMDECHO"))
  239.   (setvar "CMDECHO" 0)

  240.   ;;  get objects to break
  241.   (prompt "\nSelect object(s) to break & press enter: ")
  242.   (if (and (setq ss1 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  243.            (not (ssredraw ss1 3))
  244.            (not (prompt "\n***  Select single object to break with:  ***"))
  245.            (setq ss2 (ssget "+.:E:S" '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  246.            (not (ssredraw ss1 4))
  247.       )
  248.     (break_with ss1 ss2 nil) ; ss2break ss2breakwith (flag nil = not to break with self)
  249.   )

  250.   (setvar "CMDECHO" cmd)
  251.   (command "._undo" "_end")
  252.   (princ)
  253. )

  254. ;;==========================================
  255. ;;  Break many objects with many object     
  256. ;;==========================================
  257. (defun c:BreakWith (/ cmd ss1 ss2)
  258.   (defun ssredraw (ss mode / i num)
  259.     (setq i -1)
  260.     (while (setq ename (ssname ss (setq i (1+ i))))
  261.       (redraw (ssname ss i) mode)
  262.     )
  263.   )
  264.   (command "._undo" "_begin")
  265.   (setq cmd (getvar "CMDECHO"))
  266.   (setvar "CMDECHO" 0)

  267.   ;;  get objects to break
  268.   (prompt "\nSelect object(s) to break & press enter: ")
  269.   (if (and (setq ss1 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  270.            (not (ssredraw ss1 3))
  271.            (not (prompt "\n***  Select object(s) to break with & press enter:  ***"))
  272.            (setq ss2 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  273.            (not (ssredraw ss1 4))
  274.       )
  275.     (break_with ss1 ss2 nil) ; ss2break ss2breakwith (flag nil = not to break with self)
  276.   )

  277.   (setvar "CMDECHO" cmd)
  278.   (command "._undo" "_end")
  279.   (princ)
  280. )



  281. ;;=============================================
  282. ;;  Break many objects with a selected objects
  283. ;;  Selected Objects create ss to be broken   
  284. ;;=============================================

  285. (defun c:BreakTouching (/ cmd ss1 ss2)
  286.   
  287.   ;;  get all objects touching entities in the sscross
  288.   ;;  limited obj types to "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"
  289.   (defun gettouching (sscros / ss lst lstb lstc objl)
  290.     (and
  291.       (setq lstb (vl-remove-if 'listp (mapcar 'cadr (ssnamex sscros)))
  292.             objl (mapcar 'vlax-ename->vla-object lstb)
  293.       )
  294.       (setq
  295.         ss (ssget "_A" (list (cons 0 "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE")
  296.                              (cons 410 (getvar "ctab"))))
  297.       )
  298.       (setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  299.       (setq lst (mapcar 'vlax-ename->vla-object lst))
  300.       (mapcar
  301.         '(lambda (x)
  302.            (mapcar
  303.              '(lambda (y)
  304.                 (if (not
  305.                       (vl-catch-all-error-p
  306.                         (vl-catch-all-apply
  307.                           '(lambda ()
  308.                              (vlax-safearray->list
  309.                                (vlax-variant-value
  310.                                  (vla-intersectwith y x acextendnone)
  311.                                ))))))
  312.                   (setq lstc (cons (vlax-vla-object->ename x) lstc))
  313.                 )
  314.               ) objl)
  315.          ) lst)
  316.     )
  317.     lstc
  318.   )

  319.   (command "._undo" "_begin")
  320.   (setq cmd (getvar "CMDECHO"))
  321.   (setvar "CMDECHO" 0)
  322.   (setq ss1 (ssadd))
  323.   ;;  get objects to break
  324.   (if (and (not (prompt "\nSelect object(s) to break with & press enter: "))
  325.            (setq ss2 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  326.            (mapcar '(lambda (x) (ssadd x ss1)) (gettouching ss2))
  327.       )
  328.     (break_with ss1 ss2 nil) ; ss2break ss2breakwith (flag nil = not to break with self)
  329.   )

  330.   (setvar "CMDECHO" cmd)
  331.   (command "._undo" "_end")
  332.   (princ)
  333. )



  334. ;;==========================================================
  335. ;;  Break selected objects with any objects that touch it  
  336. ;;==========================================================


  337. (defun c:BreakSelected (/ cmd ss1 ss2)
  338.   
  339.   ;;  get all objects touching entities in the sscross
  340.   ;;  limited obj types to "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"
  341.   (defun gettouching (sscros / ss lst lstb lstc objl)
  342.     (and
  343.       (setq lstb (vl-remove-if 'listp (mapcar 'cadr (ssnamex sscros)))
  344.             objl (mapcar 'vlax-ename->vla-object lstb)
  345.       )
  346.       (setq
  347.         ss (ssget "_A" (list (cons 0 "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE")
  348.                              (cons 410 (getvar "ctab"))))
  349.       )
  350.       (setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  351.       (setq lst (mapcar 'vlax-ename->vla-object lst))
  352.       (mapcar
  353.         '(lambda (x)
  354.            (mapcar
  355.              '(lambda (y)
  356.                 (if (not
  357.                       (vl-catch-all-error-p
  358.                         (vl-catch-all-apply
  359.                           '(lambda ()
  360.                              (vlax-safearray->list
  361.                                (vlax-variant-value
  362.                                  (vla-intersectwith y x acextendnone)
  363.                                ))))))
  364.                   (setq lstc (cons (vlax-vla-object->ename x) lstc))
  365.                 )
  366.               ) objl)
  367.          ) lst)
  368.     )
  369.     lstc
  370.   )

  371.   (command "._undo" "_begin")
  372.   (setq cmd (getvar "CMDECHO"))
  373.   (setvar "CMDECHO" 0)
  374.   (setq ss1 (ssadd))
  375.   ;;  get objects to break
  376.   (if (and (not (prompt "\nSelect object(s) to break with & press enter: "))
  377.            (setq ss2 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  378.            (mapcar '(lambda (x) (ssadd x ss1)) (gettouching ss2))
  379.       )
  380.     (break_with ss2 ss1 nil) ; ss2break ss2breakwith (flag nil = not to break with self)
  381.   )

  382.   (setvar "CMDECHO" cmd)
  383.   (command "._undo" "_end")
  384.   (princ)
  385. )


  386. ;;/'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\.
  387. ;;    E n d   O f   F i l e   I f   y o u   A r e   H e r e      
  388. ;;/'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\./'\.Charles Alan Butler

点评

你好,麻烦问下,为什么有对话框的,运行时不出对话框  发表于 2023-5-9 20:06

评分

参与人数 2明经币 +2 收起 理由
500w008 + 1 谢谢大佬 又是你给我的帮助
yjr111 + 1 谢谢支持!

查看全部评分

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

本版积分规则

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

GMT+8, 2024-5-18 16:02 , Processed in 0.753296 second(s), 39 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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